package com.xoa.service.attend;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xoa.dao.attend.*;
import com.xoa.dao.attendance.AttendRuleMapper;
import com.xoa.dao.attendance.UserDutyMapper;
import com.xoa.dao.department.DepartmentMapper;
import com.xoa.dao.users.UserExtMapper;
import com.xoa.dao.users.UsersMapper;
import com.xoa.model.attend.UnitException;
import com.xoa.model.attend.*;
import com.xoa.model.attendance.AttendRule;
import com.xoa.model.attendance.UserDuty;
import com.xoa.model.department.Department;
import com.xoa.model.users.UserExt;
import com.xoa.model.users.Users;
import com.xoa.service.attend.wrapper.*;
import com.xoa.util.*;
import com.xoa.util.attend.AttendDateUtil;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.common.wrapper.BaseWrapper;
import com.xoa.util.ipUtil.IpAddr;
import com.xoa.util.page.PageParams;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.sql.*;
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Created by gsb on 2017/6/8.sss
 */
@Service
@SuppressWarnings("all")
public class AttendService {
    @Value("${upload.win}")
    private String savePath_win;

    @Value("${upload.linux}")
    private String savePath_linux;
    public final String numberZero = "0";
    public final String numberOne = "1";
    public final String numberTwo = "2";
    public final String numberThree = "3";
    public final String numberFour = "4";
    public final String numberFive = "5";
    public final String numberSix = "6";

    @Autowired
    private AttendMapper attendMapper;
    @Autowired
    private AttendSetMapper attendSetMapper;
    @Autowired
    private UserExtMapper userExtMapper;
    @Autowired
    private UsersMapper usersMapper;
    @Autowired
    private DepartmentMapper departmentMapper;
    @Autowired
    private AttendEvectionMapper attendEvectionMapper;//出差
    @Autowired
    private AttendLeaveMapper attendLeaveMapper;//请假
    @Autowired
    private AttendanceOvertimeMapper attendanceOvertimeMapper;//加班
    @Autowired
    private AttendOutMapper attendOutMapper;//外出
    @Autowired
    private AttendHolidayMapper holidayMapper;
    @Autowired
    private AttendRuleMapper attendRuleMapper;
    @Autowired
    private UserDutyMapper userDutyMapper;
    @Autowired
    private AttendMachineMapper attendMachineMapper;

    @Autowired
    private AttendConfigMapper attendConfigMapper;

    //签到签到
    public BaseWrapper newAttend(Attend attend, HttpServletRequest req) throws ParseException {
        AttendSetWrappers wrappers = new AttendSetWrappers();
        wrappers.setFlag(false);
        wrappers.setStatus(true);
        wrappers.setMsg("签到失败");
        Cookie redisSessionId = CookiesUtil.getCookieByName(req, "redisSessionId");
        Users users = SessionUtils.getSessionInfo(req.getSession(), Users.class, new Users(), redisSessionId);
        try {
            //用户当天的排班
            UserDuty userDuty = userDutyMapper.userDuty(users.getUid(), DateFormat.getDatestr(new Date()));
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("uid", users.getUid());
            map.put("date", DateFormat.getDatestr(new Date()));
            map.put("type", attend.getType());
            //用户当天的签到信息
            List<Attend> attendList = attendMapper.selectAttend(map);
            attend.setUid(users.getUid());
            boolean bol = true;
            if (userDuty != null) {
                if (userDuty.getAddType().contains("3")) {
                    //节假日无需签到
                    wrappers.setMsg("今天是节假日");
                } else {
                    //用户当天的考勤类型
                    AttendSet attendSet = attendSetMapper.selectAttendSetSid(userDuty.getDutyType());
                    if (attendSet != null) {
                        //判断是否IP限制
                        if ("1".equals(attendSet.getIpOn()) && !StringUtils.checkNull(attendSet.getIpParagraph())) {
                            bol = IpAddr.isIps(req, attendSet.getIpParagraph());
                        }
                        if (bol) {
                            attend.setDate(new Date());
                            attend.setAtime(Math.toIntExact(System.currentTimeMillis() / 1000));
                            //固定签到
                            if ("0".equals(attendSet.getAttendType())) {
                                if (!"20".equals(attend.getType()) && attendList != null && attendList.size() > 0) {
                                    wrappers.setMsg("重复签到");
                                    wrappers.setCode("130050");
                                }else if (StringUtils.checkNull(attend.getAddress())) {
                                    wrappers.setMsg("考勤签到地址不能为空");
                                    wrappers.setCode("130060");
                                } else if ("20".equals(attend.getType())) {
                                    wrappers.setMsg("签到方式错误");
                                } else {
                                    int res = attendMapper.addAttend(attend);
                                    if (res == 1) {
                                        wrappers.setFlag(true);
                                        wrappers.setStatus(true);
                                        wrappers.setMsg("签到成功");
                                    }
                                }
                            } else {
                                //自由签到
                                if (StringUtils.checkNull(attend.getPhoneId()))
                                    attend.setPhoneId("PC");
                                if (StringUtils.checkNull(attend.getDevice()))
                                    attend.setDevice("PC");
                                if (StringUtils.checkNull(attend.getAddress()))
                                    attend.setAddress("网页签到");
                                if (!"20".equals(attend.getType())) {
                                    wrappers.setMsg("签到方式错误");
                                }
                                if (!AttendDateUtil.CalTimeRange(attendSet.getWorkStart(), attendSet.getWorkEnd())) {
                                    wrappers.setMsg("当前时间不允许签到");
                                } else {
                                    int res = attendMapper.addAttend(attend);
                                    if (res == 1) {
                                        wrappers.setFlag(true);
                                        wrappers.setStatus(true);
                                        wrappers.setMsg("签到成功");
                                    }
                                }
                            }
                        } else {
                            wrappers.setMsg("IP地址未在规定范围内");
                        }
                    } else {
                        wrappers.setMsg("考勤类型已删除");
                    }
                }
            } else {
                wrappers.setMsg("今天不需要考勤");
            }
        } catch (Exception e) {
            e.printStackTrace();
            wrappers.setMsg(e.getMessage());
        }
        return wrappers;
    }


    public BaseWrapper addAttendance() throws ParseException {//考勤机实现考勤
        //int max = attendMapper.selectMaxId();//获取最大的id
        Attend attend = new Attend();
        AttendSetWrappers wrappers = new AttendSetWrappers();
        String url = "http://127.0.0.1:88/api/v2/transaction/get/?key=34caai0tm1ajpduoy5gxoaihapdebynbslg7rnqo38np";
        Map<String, Object> maps = new HashMap<String, Object>();
        /*maps.put("id", 1);
        maps.put("number", 1000);*/

        //每日开始时间  starttime
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String starttime = format.format(new Date()) + " 00:00:00";
        //每日结束时间时间  endtime
        String endtime = format.format(new Date()) + " 23:59:59";

        maps.put("starttime", starttime);
        maps.put("endtime", endtime);
        String param = JSONObject.toJSONString(maps);
        String result = Test.sendPost(url, param);
        JSONArray json = new JSONArray();
        Map sysIdsMap = json.parseObject(result, Map.class);
        String data = sysIdsMap.get("data").toString();
        Map sysIds = json.parseObject(data, Map.class);

        String items = sysIds.get("items").toString();
        List list = json.parseObject(items, List.class);
        //Map sysId= json.parseObject(data,Map.class);
        for (int i = 0; i < list.size(); i++) {
            String quan = list.get(i).toString();
            Map values = json.parseObject(quan, Map.class);
            String pin = values.get("pin").toString();//byname
            String checktimepin = values.get("checktime").toString();//签到时间
            String stateno = values.get("stateno").toString();//上班还是下班 0上班  1下班

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = null;
            try {
                date = simpleDateFormat.parse(checktimepin);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            long ts = date.getTime();
            int a = Integer.valueOf(String.valueOf(ts).substring(0, 10));
            attend.setAtime(a);//时间戳类型
            try {
                attend.setUid(usersMapper.getUsersBybyname(pin).getUid());
            } catch (Exception e) {
                e.printStackTrace();
                wrappers.setMsg("人员有问题");
            }

            attend.setDate(DateFormat.DateToStr(checktimepin));//设置时间yyyy-MM-dd
            attend.setAddress("考勤机");//地址
            attend.setRemark("考勤机");//备注
            attend.setPhoneId("kaoqinji");//
            attend.setDevice("XFace600");

            Long ka = null;
            SimpleDateFormat Daka = new SimpleDateFormat("HH:mm:ss");
            String format1 = Daka.format(date);

            try {
                ka = Daka.parse(format1).getTime();//截取到时分秒  签到时间
            } catch (Exception e) {

            }

            //取排班类型及上下班登记时间----开始---
            AttendConfig attendConfig = attendConfigMapper.getDutyType(pin);//'考勤排班类型(1-正常班,2-全日班,99-轮班制)'
            SimpleDateFormat shifenmiao = new SimpleDateFormat("HH:mm:ss");
            long Dutytime1 = 0;
            if (!StringUtils.checkNull(attendConfig.getDutyTime1())) {
                Date parse = shifenmiao.parse(attendConfig.getDutyTime1());
                Dutytime1 = shifenmiao.parse(attendConfig.getDutyTime1()).getTime();
            }
            long Dutytime2 = 0;
            if (!StringUtils.checkNull(attendConfig.getDutyTime2())) {
                Dutytime2 = shifenmiao.parse(attendConfig.getDutyTime2()).getTime();
            }
            long Dutytime3 = 0;
            if (!StringUtils.checkNull(attendConfig.getDutyTime3())) {
                long time3 = Daka.parse(attendConfig.getDutyTime3()).getTime();
            }
            long Dutytime4 = 0;
            if (!StringUtils.checkNull(attendConfig.getDutyTime4())) {
                long time4 = shifenmiao.parse(attendConfig.getDutyTime4()).getTime();
            }
            long Dutytime5 = 0;
            if (!StringUtils.checkNull(attendConfig.getDutyTime5())) {
                long time5 = shifenmiao.parse(attendConfig.getDutyTime5()).getTime();
            }
            long Dutytime6 = 0;
            if (!StringUtils.checkNull(attendConfig.getDutyTime6())) {
                long time6 = shifenmiao.parse(attendConfig.getDutyTime6()).getTime();
            }


            if (Dutytime1 - 1800000 <= ka && ka <= Dutytime1 + 1800000) {
                attend.setType("1");//第一次签到 上班
            }
            if (Dutytime2 - 1800000 <= ka && ka <= Dutytime2 + 1800000) {
                attend.setType("2");//第二次签到 下班
            }
            if (Dutytime3 - 1800000 <= ka && ka <= Dutytime3 + 1800000) {
                attend.setType("3");//第三次签到 上班
            }
            if (Dutytime4 - 1800000 <= ka && ka <= Dutytime4 + 1800000) {
                attend.setType("4");//第四次签到 下班
            }
            if (Dutytime5 - 1800000 <= ka && ka <= Dutytime5 + 1800000) {
                attend.setType("5");//第五次签到 上班
            }
            if (Dutytime6 - 1800000 <= ka && ka <= Dutytime6 + 1800000) {
                attend.setType("6");//第六次签到 下班
            }
            attendMapper.insertSelective(attend);
        }
        return wrappers;
    }

    public ResultSet moveData(String sql) {
        ToJson<ResultSet> json = new ToJson<ResultSet>(1, "err");
        PreparedStatement ps = null;
        ResultSet resultSet = null;
        try {
            Connection conn = null;
            // 驱动程序名
            String driver = "com.mysql.jdbc.Driver";
            // URL指向要访问的数据库名 test
            String url = "jdbc:mysql://127.0.0.1:33060/zkeco?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true";
            // MySQL配置时的用户名
            String UserName = "root";
            // MySQL配置时的密码
            String Password = "";
            /*String url = "jdbc:oracle:thin:@192.168.0.38:1521:xoa";// 数据库连接，oracle代表链接的是oracle数据库；thin:@MyDbComputerNameOrIP代表的是数据库所在的IP地址（可以保留thin:）；1521代表链接数据库的端口号；ORCL代表的是数据库名称
            String UserName = "xoa_test";// 数据库用户登陆名 ( 也有说是 schema 名字的 )
            String Password = "myoa888";// 密码*/
            // 加载驱动程序
            try {
                Class.forName(driver);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            // 1.getConnection()方法，连接MySQL数据库！！
            //con = DriverManager.getConnection(url, user, password);
            conn = DriverManager.getConnection(url, UserName, Password);

            //String sql = "select * from OA_FLOW_REPORT";// 签报表
            ps = conn.prepareStatement(sql);// 实例化预编译语句
            resultSet = ps.executeQuery();// 执行查询


            json.setMsg("ok");
            json.setFlag(0);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return resultSet;

    }

    public BaseWrapper addAttendances() throws ParseException, SQLException {//考勤机实现考勤 连接数据库
        Attend attend = new Attend();
        AttendSetWrappers wrappers = new AttendSetWrappers();

        //每日开始时间  starttime
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String starttime = format.format(new Date()) + " 00:00:00";
        //每日结束时间时间  endtime
        String endtime = format.format(new Date()) + " 23:59:59";

        String sql = "SELECT checkinout.*,userinfo.badgenumber from checkinout LEFT JOIN userinfo on userinfo.userid = checkinout.userid " +
                "where checktime <=" + "'" + endtime + "'" + " and checktime >=" + "'" + starttime + "'";

        ResultSet resultSet = moveData(sql);
        while (resultSet.next()) {
            HashMap<Object, Object> map = new HashMap<Object, Object>();
            String byname = resultSet.getString("badgenumber") == null ? "" : resultSet.getString("badgenumber");//人员id
            String checktime = resultSet.getString("checktime") == null ? "" : resultSet.getString("checktime");//签到时间
            String checktimes = checktime.substring(0, 19);//对返回数据进行截取
            try {
                attend.setUid(usersMapper.getUsersBybyname(byname).getUid());
            } catch (Exception e) {
                e.printStackTrace();
                wrappers.setMsg("人员有问题");
            }

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = null;
            try {
                date = simpleDateFormat.parse(checktimes);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            long ts = date.getTime();
            int a = Integer.valueOf(String.valueOf(ts).substring(0, 10));
            attend.setAtime(a);//时间戳类型
            attend.setDate(DateFormat.DateToStr(checktimes));//设置时间yyyy-MM-dd
            attend.setAddress("考勤机");//地址
            attend.setRemark("考勤机");//备注
            attend.setPhoneId("kaoqinji");//
            attend.setDevice("XFace600");

            Long ka = null;//签到时间  只截取时分秒
            SimpleDateFormat Daka = new SimpleDateFormat("HH:mm:ss");
            String format1 = Daka.format(date);

            try {
                ka = Daka.parse(format1).getTime();//截取到时分秒  签到时间  int类型
            } catch (Exception e) {

            }

            //取排班类型及上下班登记时间----开始---
            AttendConfig attendConfig = attendConfigMapper.getDutyType(byname);//'考勤排班类型(1-正常班,2-全日班,99-轮班制)'
            SimpleDateFormat shifenmiao = new SimpleDateFormat("HH:mm:ss");
            long Dutytime1 = 0;
            if (!StringUtils.checkNull(attendConfig.getDutyTime1())) {
                Date parse = shifenmiao.parse(attendConfig.getDutyTime1());
                Dutytime1 = shifenmiao.parse(attendConfig.getDutyTime1()).getTime();
            }
            long Dutytime2 = 0;
            if (!StringUtils.checkNull(attendConfig.getDutyTime2())) {
                Date parse = shifenmiao.parse(attendConfig.getDutyTime2());
                Dutytime2 = shifenmiao.parse(attendConfig.getDutyTime2()).getTime();
            }
            long Dutytime3 = 0;
            if (!StringUtils.checkNull(attendConfig.getDutyTime3())) {
                Date parse = shifenmiao.parse(attendConfig.getDutyTime3());
                Dutytime3 = Daka.parse(attendConfig.getDutyTime3()).getTime();
            }
            long Dutytime4 = 0;
            if (!StringUtils.checkNull(attendConfig.getDutyTime4())) {
                Date parse = shifenmiao.parse(attendConfig.getDutyTime4());
                Dutytime4 = shifenmiao.parse(attendConfig.getDutyTime4()).getTime();
            }
            long Dutytime5 = 0;
            if (!StringUtils.checkNull(attendConfig.getDutyTime5())) {
                Date parse = shifenmiao.parse(attendConfig.getDutyTime5());
                Dutytime5 = shifenmiao.parse(attendConfig.getDutyTime5()).getTime();
            }
            long Dutytime6 = 0;
            if (!StringUtils.checkNull(attendConfig.getDutyTime6())) {
                Date parse = shifenmiao.parse(attendConfig.getDutyTime6());
                Dutytime6 = shifenmiao.parse(attendConfig.getDutyTime6()).getTime();
            }


            if (Dutytime1 - 1800000 <= ka && ka <= Dutytime1 + 1800000) {
                attend.setType("1");//第一次签到 上班
            }
            if (Dutytime2 - 1800000 <= ka && ka <= Dutytime2 + 1800000) {
                attend.setType("2");//第二次签到 下班
            }
            if (Dutytime3 - 1800000 <= ka && ka <= Dutytime3 + 1800000) {
                attend.setType("3");//第三次签到 上班
            }
            if (Dutytime4 - 1800000 <= ka && ka <= Dutytime4 + 1800000) {
                attend.setType("4");//第四次签到 下班
            }
            if (Dutytime5 - 1800000 <= ka && ka <= Dutytime5 + 1800000) {
                attend.setType("5");//第五次签到 上班
            }
            if (Dutytime6 - 1800000 <= ka && ka <= Dutytime6 + 1800000) {
                attend.setType("6");//第六次签到 下班
            }

            UserDuty userDuty = new UserDuty();
            userDuty.setUid(attend.getUid());
            userDuty.setDutyDate(format.format(attend.getDate()));
            userDuty.setDutyType(Integer.valueOf(attend.getType()));
            userDutyMapper.insertSelective(userDuty);//个人考勤

            attendMapper.insertSelective(attend);
        }
        return wrappers;
    }

    //获取签到页面所需数据
    public BaseWrapper attendList(String attendDate, Integer uid, String sqlType) {
        AttendSetWrappers wrappers = new AttendSetWrappers();
        //考勤统计权限
        wrappers.setCode("1");
        try {
            Attend attend = new Attend();
            //用户当天的固定签到信息按照类型分开
            Map<String, Attend> mapAttend = new HashMap<String, Attend>();
            //用户当天的自由签到信息
            List<Attend> attendList = new ArrayList();
            if (uid != null) {
                //用户排班
                UserDuty userDuty = userDutyMapper.userDuty(uid, attendDate);
                if (userDuty != null) {
                    //用户考勤类型
                    AttendSet attendSet = attendSetMapper.selectAttendSetSid(userDuty.getDutyType());
                    //用户当天的签到信息
                    List<Attend> attendLists = attendMapper.getAttendByUidDate(attendDate, uid);
                    for (Attend attends : attendLists) {
                        if ("20".equals(attends.getType())) {
                            attendList.add(attends);
                        } else {
                            mapAttend.put(attends.getType(), attends);
                        }
                    }
                    //考勤统计规则
                    //考勤规则
                    //单次迟到分钟为旷工
                    Integer oneLateHour = null;
                    //单次迟到早退为旷工
                    Integer oneEarlyHour = null;
                    long oneLateHourLong = 0;
                    long oneEarlyHourLong = 0;
                    List<AttendRule> attendRuleList = null;
                    Users user = usersMapper.getByUid(Integer.valueOf(uid));
                    if (user.getDeptId() != null) {
                        attendRuleList = attendRuleMapper.getAttendRuleByDept(user.getDeptId());
                        for (AttendRule attendRule : attendRuleList) {
                            oneLateHour = attendRule.getOneLateHour();
                            oneEarlyHour = attendRule.getOneEarlyHour();
                            oneLateHourLong = new Long(oneLateHour).longValue() * 60 * 1000;
                            oneEarlyHourLong = new Long(oneEarlyHour).longValue() * 60 * 1000;
                        }
                    }
                    if (attendSet != null) {
                        setAttendSet(attendSet);
                        List<Attend> legwork = new ArrayList<Attend>();
                        List<Attend> overTimeWork = new ArrayList<Attend>();
                        List<Attend> dutyWork = new ArrayList<Attend>();
                        List<Attend> workList = new ArrayList<Attend>();
                        if ("0".equals(attendSet.getAttendType())) {
                            Class c = attendSet.getClass().forName("com.xoa.model.attend.AttendSet");
                            c.newInstance();
                            for (int i = 1; i <= 6; i++) {
                                //分别取出 开关 和上下班类型
                                Method methodget = c.getMethod("getAtime" + i + "Set");
                                String getAtimeSet = (String) methodget.invoke(attendSet);
                                String[] getAtimeSets = getAtimeSet.split("\\|");
                                String setother = getAtimeSets[0];
                                String commute = getAtimeSets[1];
                                //如果启动
                                if (setother.equals("1")) {
                                    Method methodGetAtime = c.getMethod("getAtime" + i);
                                    //应签到时间 时间戳（秒）
                                    String getAtime = (String) methodGetAtime.invoke(attendSet);
                                    String time = getAtime;
                                    String status = "";
                                    String remark = "";
                                    String addres = "";
                                    getAtime = userDuty.getDutyDate() + " " + getAtime;
                                    Integer yAtime = DateFormat.getNowDateTime(getAtime);
                                    int atime = yAtime;
                                    //查看的签到信息
                                    if (mapAttend != null) {
                                        Attend dutyAttend = mapAttend.get(String.valueOf(i));
                                        //如果有签到，查看是否正常
                                        if (dutyAttend != null) {
                                            //注意，此为秒级时间戳.签到时间
                                            atime = dutyAttend.getAtime();
                                            if (commute.equals("1")) {
                                                if (atime > yAtime) {
                                                    status = "迟到";
                                                } else {
                                                    status = "正常";
                                                }
                                            } else if (commute.equals("2")) {
                                                if (atime < yAtime) {
                                                    status = "早退";
                                                } else {
                                                    status = "正常";
                                                }
                                            }
                                            remark = dutyAttend.getRemark();
                                            addres = dutyAttend.getAddress();
                                            time = DateFormat.getwyqStrTime(atime);
                                        } else {
                                            status = "未签到";
                                        }
                                    } else {
                                        status = "未签到";
                                    }
                                    Attend attendRetur = new Attend();
                                    attendRetur.setNum(String.valueOf(i));
                                    attendRetur.setSwi(numberOne);
                                    attendRetur.setDateName(userDuty.getDutyDate());
                                    attendRetur.setCommute(commute);
                                    attendRetur.setAtime(atime);
                                    attendRetur.setTime(time);
                                    attendRetur.setRemark(remark);
                                    attendRetur.setAddress(addres);
                                    attendRetur.setAtimestate(status);
                                    workList.add(attendRetur);
                                }
                            }
                            //弹性工时
                        } else if ("1".equals(attendSet.getAttendType())) {
                            if (attendList.size() > 0) {
                                //展示信息
                                String status = "";
                                //实际签到时间("HH:mm:ss"),未签到的话 就是 应签到时间
                                String time = "";
                                int i = 0;
                                Integer startTime = 0;
                                do {
                                    Attend dutyAttend = attendList.get(i);
                                    dutyAttend.setNum(numberOne);
                                    dutyAttend.setSwi(numberOne);
                                    dutyAttend.setDateName(userDuty.getDutyDate());
                                    dutyAttend.setAttendSetType(attendSet.getAttendType());
                                    dutyAttend.setAttendStatus(numberZero);
                                    dutyAttend.setWorkHours(attendSet.getWorkHours() + "小时");
                                    //计算工作时长
                                    if (startTime != 0) {
                                        Integer timea = dutyAttend.getAtime() - startTime;
                                        String workHours = DateFormat.returnTime(timea);
                                        dutyAttend.setIsFullAttend(timea >= Integer.valueOf(attendSet.getWorkHours()) * 60 * 60);
                                        dutyAttend.setActualWorkHours(workHours);
                                    }
                                    startTime = dutyAttend.getAtime();
                                    status = i == 0 ? "第一次签到" : "最后一次签到";
                                    String sstr = "1";
                                    sstr = i == 0 ? "1" : "2";
                                    dutyAttend.setCommute(sstr);
                                    time = DateFormat.getwyqStrTime(startTime);
                                    dutyAttend.setAtimestate(status);
                                    dutyAttend.setTime(time);
                                    workList.add(dutyAttend);
                                    i += attendList.size() - 1;
                                }
                                while (i != 0 && i + 1 == attendList.size());
                            } else {
                                Attend attendRetur = new Attend();
                                attendRetur.setNum("-1");
                                attendRetur.setSwi("-1");
                                attendRetur.setDateName(userDuty.getDutyDate());
                                attendRetur.setAttendSetType(attendSet.getAttendType());
                                attendRetur.setAttendStatus("-1");
                                attendRetur.setAtimestate("还未签到");
                                attendRetur.setCommute("1");
                                attendRetur.setAddress("");
                                attendRetur.setAtime(0);
                                attendRetur.setTime("0");
                                attendRetur.setRemark("");
                                workList.add(attendRetur);
                            }
                        }
                        //外勤
                        if (numberOne.equals(attendSet.getIsOut())) {
                            List<Attend> attend0 = attendMapper.selectAttend0(attendDate, uid);
                            if (attend0 != null) {
                                for (Attend a : attend0) {
                                    if (!StringUtils.checkNull(a.getFileId()) && !StringUtils.checkNull(a.getFileName())) {
                                        a.setAttachment(GetAttachmentListUtil.returnAttachment(a.getFileName(), a.getFileId(), sqlType, GetAttachmentListUtil.MODULE_ATTEND));
                                    }
                                    legwork.add(a);
                                }
                            }
                        }
                        //加班上班
                        if (numberOne.equals(attendSet.getIsOvertime())) {
                            Attend attendOverUp = attendMapper.selectAttendAll(attendDate, uid, "7");
                            if (attendOverUp != null) {
                                attendOverUp.setCommute("1");
                                attendOverUp.setAtimestate( "加班上班");
                                overTimeWork.add(attendOverUp);
                            }
                        }
                        //加班下班
                        if (numberOne.equals(attendSet.getIsOvertime())) {
                            Attend attendOverLo = attendMapper.selectAttendAll(attendDate, uid, "8");
                            if (attendOverLo != null) {
                                attendOverLo.setCommute("2");
                                attendOverLo.setAtimestate("加班下班");
                                overTimeWork.add(attendOverLo);
                            }
                        }
                        //值班上班
                        if (numberOne.equals(attendSet.getIsDuty())) {
                            Attend attendDutyUp = attendMapper.selectAttendAll(attendDate, uid, "9");
                            if (attendDutyUp != null) {
                                attendDutyUp.setCommute("1");
                                attendDutyUp.setAtimestate("值班上班");
                                dutyWork.add(attendDutyUp);
                            }
                        }
                        //值班下班
                        if (numberOne.equals(attendSet.getIsDuty())) {
                            Attend attendDutyLo = attendMapper.selectAttendAll(attendDate, uid, "10");
                            if (attendDutyLo != null) {
                                attendDutyLo.setAtimestate("值班下班");
                                attendDutyLo.setCommute("2");
                                dutyWork.add(attendDutyLo);
                            }
                        }
                        attend.setDate(DateFormat.DateToStr(attendDate));
                        attend.setAttendSet(attendSet);
                        attend.setAttendList(workList);
                        attend.setLegwork(legwork);
                        attend.setOverTimeWork(overTimeWork);
                        attend.setDutyWork(dutyWork);
                        wrappers.setFlag(true);
                        wrappers.setStatus(true);
                        wrappers.setData(attend);
                        wrappers.setMsg("成功");
                    } else {
                        wrappers.setMsg("无类型");
                    }
                } else {
                    wrappers.setMsg("无需签到");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            wrappers.setMsg(e.getMessage());
        }
        return wrappers;
    }

    // 查询当天用户签到的前十个用户
    public BaseWrapper mycheckList(String date) {
        AttendSetWrappers wrappers = new AttendSetWrappers();
        Map<String, Object> map = new HashMap<String, Object>();
        PageParams pageParams = new PageParams();
        pageParams.setUseFlag(true);
        pageParams.setPage(1);
        pageParams.setPageSize(10);
        map.put("page", pageParams);
        map.put("date", date);
        List<Attend> attendList = attendMapper.AttendList(map);
        Iterator<Attend> attendIterator = attendList.iterator();
        while (attendIterator.hasNext()) {
            Attend attend = attendIterator.next();
            Users users = usersMapper.getByUid(attend.getUid());
            if (users != null) {
                attend.setSname(users.getUserName());
                attend.setAva(users.getAvatar());
            } else {
                attendIterator.remove();
            }
        }
        if (attendList != null) {
            wrappers.setData(attendList);
            wrappers.setFlag(true);
            wrappers.setStatus(true);
            wrappers.setMsg("更新成功");
        } else {
            wrappers.setFlag(true);
            wrappers.setStatus(false);
            wrappers.setMsg("更新失败");
        }
        return wrappers;
    }

    //我的考勤统计
    public BaseWrapper myAttend(String start, HttpServletRequest req) throws ParseException {
        AttendSetWrappers wrappers = new AttendSetWrappers();
        Cookie redisSessionId = CookiesUtil.getCookieByName(req, "redisSessionId");
        String sqlType = "xoa"+SessionUtils.getSessionInfo(req.getSession(), "loginDateSouse", String.class, redisSessionId);
        Users users = SessionUtils.getSessionInfo(req.getSession(), Users.class, new Users(), redisSessionId);
        Integer uid = users.getUid();
        try {
            Attend attend = new Attend();
            List<Attend> workList = new ArrayList<Attend>();
            List<BaseAttend> attendances = new ArrayList<BaseAttend>();//出勤(天数)
            List<BaseAttend> normals = new ArrayList<BaseAttend>();//正常签到(次数)
            List<BaseAttend> normalNews = new ArrayList<BaseAttend>();//正常签到(天数)

            List<BaseAttend> fields = new ArrayList<BaseAttend>();//外勤(次数)
            List<BaseAttend> lates = new ArrayList<BaseAttend>();//迟到(次数)
            List<BaseAttend> leaveEarlies = new ArrayList<BaseAttend>();//早退(次数)
            List<BaseAttend> lackCards = new ArrayList<BaseAttend>();//缺卡(次数)

            List<BaseAttend> absenteeisms = new ArrayList<BaseAttend>();//旷工
            List<BaseAttend> unitExceptionList = new ArrayList<BaseAttend>();//设备异常
            List<BaseAttend> attendOutList = new ArrayList<BaseAttend>();//外出
            List<BaseAttend> attendLeaveList = new ArrayList<BaseAttend>();//请假
            List<BaseAttend> attendEvectionList = new ArrayList<BaseAttend>();//出差
            List<BaseAttend> attendanceOvertimeList = new ArrayList<BaseAttend>();//加班*值班

            List<BaseAttend> lateRecord = new ArrayList<BaseAttend>();//迟到记录
            List<BaseAttend> leaveEarlyRecord = new ArrayList<BaseAttend>();//早退记录
            List<BaseAttend> lackCardRecord = new ArrayList<BaseAttend>();//缺卡记录
            List<BaseAttend> absenteeismRecord = new ArrayList<BaseAttend>();//旷工记录

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
            List<String> monthMaxDay = new ArrayList<>();
            if (simpleDateFormat.format(new Date()).equals(start)) {
                monthMaxDay = AttendDateUtil.getMonthMaxDay();
            } else {
                monthMaxDay = AttendDateUtil.getMonthMaxDay(start);
            }
            String startDate = monthMaxDay.get(0);
            String endDate = monthMaxDay.get(monthMaxDay.size() - 1);
            //签到设备异常
            unitExceptionList = myAttendUnitException(startDate, endDate, uid, req);
            //用户的排班信息
            List<UserDuty> userDutyList = userDutyMapper.getUserDutyListByUidAndDates(uid, startDate, endDate);
            //根据uid和日期查找用户的固定签到信息
            List<Attend> attendList = attendMapper.getAttendListByUidAndDates(uid, startDate, endDate);
            //根据uid和日期查找用户的自由签到信息
            List<Attend> attendByUidDatesType = attendMapper.getAttendByUidDatesType(uid, startDate, endDate);
            //固定签到信息按日期分组
            Map<String, Map<String, Attend>> groudAttendMap = groudAttendByDateType(attendList);
            //自由签到信息按日期分组
            Map<String, List<Attend>> stringListMap = groudAttendByDate(attendByUidDatesType);
            //临时存储考勤类型
            Map<Integer, AttendSet> attendSetMap = new HashMap();
            for (UserDuty userDuty : userDutyList) {
                if (userDuty != null) {
                    String nowStr = userDuty.getDutyDate();
                    Date nowDate = DateFormat.getDates(nowStr);
                    //外出统计
                    List<AttendOut> attendOuts = attendOutMapper.queryAttendOut(users.getUserId(), nowStr);
                    if (attendOuts.size() > 0 && attendOuts != null) {
                        Iterator<AttendOut> attendOutIterator = attendOuts.iterator();
                        while (attendOutIterator.hasNext()) {
                            AttendOut attendOut = attendOutIterator.next();
                            BaseAttend attendOutNew = new BaseAttend();
                            attendOutNew.setStrat(attendOut.getOutTime1());
                            attendOutNew.setEnd(attendOut.getOutTime2());
                            attendOutNew.setStr("原因:" + attendOut.getOutType());
                            attendOutNew.setHour("1");
                            attendOutList.add(attendOutNew);
                        }
                    }
                    //请假统计
                    List<AttendLeave> attendLeaves = attendLeaveMapper.selectAttendLeaveModify(users.getUserId(), nowStr);
                    if (attendLeaves.size() > 0 && attendLeaves != null) {
                        Iterator<AttendLeave> attendLeavesIteratorr = attendLeaves.iterator();
                        while (attendLeavesIteratorr.hasNext()) {
                            AttendLeave attendLeave = attendLeavesIteratorr.next();
                            BaseAttend attendLeaveNew = new BaseAttend();
                            attendLeaveNew.setStrat(DateFormat.getStrDate(attendLeave.getLeaveDate1()));
                            attendLeaveNew.setEnd(DateFormat.getStrDate(attendLeave.getLeaveDate2()));
                            attendLeaveNew.setStr("原因:" + attendLeave.getLeaveType());
                            attendLeaveNew.setHour("1");
                            attendLeaveList.add(attendLeaveNew);
                        }
                    }
                    //出差统计
                    List<AttendEvection> attendEvections = attendEvectionMapper.selectAttendEvectionModify(users.getUserId(), nowStr);
                    if (attendEvections.size() > 0 && attendEvections != null) {
                        Iterator<AttendEvection> attendEvectionIterator = attendEvections.iterator();
                        while (attendEvectionIterator.hasNext()) {
                            AttendEvection attendEvection = attendEvectionIterator.next();
                            BaseAttend attendEvectionNew = new BaseAttend();
                            attendEvectionNew.setStrat(DateFormat.getStrDate(attendEvection.getEvectionDate1()));
                            attendEvectionNew.setEnd(DateFormat.getStrDate(attendEvection.getEvectionDate2()));
                            attendEvectionNew.setStr("原因:" + attendEvection.getReason());
                            attendEvectionNew.setHour("1");
                            attendEvectionList.add(attendEvectionNew);
                        }
                    }
                    //加班*值班
                    boolean jiaban = false;
                    List<Attend> attends = attendMapper.getJiaBanZhiBanListByUidsAndDate(new ArrayList<Integer>(Arrays.asList(users.getUid())), nowStr);
                    BaseAttend attendanceOvertimeNew = new BaseAttend();
                    attendanceOvertimeNew.setStrat("");
                    attendanceOvertimeNew.setEnd("");
                    attendanceOvertimeNew.setStr("");
                    attendanceOvertimeNew.setHour("");
                    for (Attend a : attends) {
                        if (a.getType().equals("7")) {
                            jiaban = true;
                            attendanceOvertimeNew.setStrat(DateFormat.getStrTime(a.getAtime()));
                        }
                        if (a.getType().equals("8")) {
                            jiaban = true;
                            attendanceOvertimeNew.setEnd(DateFormat.getStrTime(a.getAtime()));
                        }
                    }
                    if (jiaban)attendanceOvertimeList.add(attendanceOvertimeNew);

                    Attendance attendance = new Attendance();//出勤
                    Absenteeism absenteeism = new Absenteeism();//旷工
                    LeaveEarly leaveEarly = new LeaveEarly();//早退
                    Normal normal = new Normal();//正常
                    Late late = new Late();//迟到
                    LackCard lackCard = new LackCard();//缺卡
                    Normal normalNew = new Normal();//正常判断

                    //获取考勤类型
                    Integer userDutyType = userDuty.getDutyType();
                    AttendSet attendSet = attendSetMap.get(userDutyType);
                    if (attendSet == null) {
                        attendSet = attendSetMapper.selectAttendSetSid(userDutyType);
                        setAttendSet(attendSet);
                        attendSetMap.put(userDutyType, attendSet);
                    }
                    //用户一天的考勤信息
                    List<Attend> attendListDate = stringListMap.get(nowStr);
                    if (attendListDate != null && attendListDate.size() > 0) {
                        attendance.setWeek(DateCompute.getWeekOfDate(nowDate));
                        attendance.setDate(DateFormat.getDatestrTime(nowDate));
                        attendances.add(attendance);
                    } else {//如果日期不是今天
                        if (!nowStr.equals(DateFormat.getCurrentTime2())) {
                            //出差
                            List<AttendEvection> attendEvection = attendEvectionMapper.selectAttendEvectionModify(users.getUserId(), nowStr);
                            //请假
                            List<AttendLeave> attendLeave = attendLeaveMapper.selectAttendLeaveModify(users.getUserId(), nowStr);
                            if (attendEvection.size() == 0 && attendEvection.size() == 0) {
                                Absenteeism absenteeismRecords = new Absenteeism();
                                absenteeism.setWeek(DateCompute.getWeekOfDate(nowDate));
                                absenteeism.setDate(DateFormat.getDatestrTime(nowDate));
                                absenteeismRecords.setWeek(DateCompute.getWeekOfDate(nowDate));
                                absenteeismRecords.setDate(DateFormat.getDatestrTime(nowDate));
                                absenteeisms.add(absenteeism);
                                absenteeismRecord.add(absenteeismRecords);
                            }
                        }
                    }
                    //每天需要签到次数
                    int xqhbt = 0;
                    if (numberOne.equals(attendSet.getAtime1Setother())) xqhbt++;
                    if (numberOne.equals(attendSet.getAtime2Setother())) xqhbt++;
                    if (numberOne.equals(attendSet.getAtime3Setother())) xqhbt++;
                    if (numberOne.equals(attendSet.getAtime4Setother())) xqhbt++;
                    if (numberOne.equals(attendSet.getAtime5Setother())) xqhbt++;
                    if (numberOne.equals(attendSet.getAtime6Setother())) xqhbt++;
                    ///外勤
                    if (numberOne.equals(attendSet.getIsOut())) {
                        List<Attend> attend0 = attendMapper.selectAttend0(DateFormat.getDatestr(nowDate), uid);
                        if (attend0 != null && attend0.size() > 0) {
                            Iterator<Attend> attendIterator = attend0.iterator();
                            while (attendIterator.hasNext()) {
                                Field field = new Field();//外勤
                                Attend attend1 = attendIterator.next();
                                field.setDate(DateFormat.getDatestrTime(nowDate));
                                field.setTime(DateFormat.getwyqStrTime(attend1.getAtime()));
                                field.setStr(attend1.getAddress());
                                field.setPhoneId(attend1.getPhoneId());
                                field.setCause(attend1.getRemark());
                                fields.add(field);
                            }
                        }
                    }


                    if (numberOne.equals(attendSet.getAtime1Setother())) {
                        String status = "";
                        Late latefirst = new Late();//迟到
                        Normal normalfirst = new Normal();//正常
                        LeaveEarly leaveEarlyfirst = new LeaveEarly();//早退
                        LeaveEarly leaveEarlyfirstRecord = new LeaveEarly();//早退
                        Late latefirstRecord = new Late();//迟到
                        Attend attend1 = attendMapper.selectAttendAll(nowStr, uid, numberOne);
                        if (attend1 != null) {
                            if (numberOne.equals(attend1.getType())) {
                                if (numberOne.equals(attendSet.getCommute1())) {
                                    String a1 = DateFormat.getwyqStrTime(attend1.getAtime());
                                    if (this.reTime(attend1.getAtime()) > DateFormat.getDateTimes(attendSet.getAtime1()).getTime()) {
                                        status = "迟到";
                                        latefirst.setTime(DateFormat.getwyqStrTime(attend1.getAtime()));
                                        latefirst.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        latefirst.setDate(DateFormat.getDatestrTime(nowDate));
                                        latefirst.setStr("迟到(" + DateFormat.parseMillisecone(this.reTime(attend1.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime1())) + ")");
                                        latefirst.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime1());
                                        latefirstRecord.setTime(DateFormat.getwyqStrTime(attend1.getAtime()));
                                        latefirstRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        latefirstRecord.setDate(DateFormat.getDatestrTime(nowDate));
                                        latefirstRecord.setStr("迟到(" + DateFormat.parseMillisecone(this.reTime(attend1.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime1())) + ")");
                                        latefirstRecord.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime1());
                                        lates.add(latefirst);
                                        lateRecord.add(latefirstRecord);
                                    } else {
                                        status = "正常";
                                        normalfirst.setTime(DateFormat.getwyqStrTime(attend1.getAtime()));
                                        normalfirst.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        normalfirst.setDate(DateFormat.getDatestrTime(nowDate));
                                        normals.add(normalfirst);
                                    }
                                } else {
                                    String a1 = DateFormat.getwyqStrTime(attend1.getAtime());
                                    if (this.reTime(attend1.getAtime()) < DateFormat.getDateTimes(attendSet.getAtime1()).getTime()) {
                                        status = "早退";
                                        leaveEarlyfirst.setTime(DateFormat.getwyqStrTime(attend1.getAtime()));
                                        leaveEarlyfirst.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        leaveEarlyfirst.setDate(DateFormat.getDatestrTime(nowDate));
                                        leaveEarlyfirst.setStr("早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime1()) - this.reTime(attend1.getAtime())) + ")");
                                        leaveEarlyfirst.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime1());
                                        leaveEarlyfirstRecord.setTime(DateFormat.getwyqStrTime(attend1.getAtime()));
                                        leaveEarlyfirstRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        leaveEarlyfirstRecord.setDate(DateFormat.getDatestrTime(nowDate));
                                        leaveEarlyfirstRecord.setStr("早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime1()) - this.reTime(attend1.getAtime())) + ")");
                                        leaveEarlyfirstRecord.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime1());
                                        leaveEarlies.add(leaveEarlyfirst);
                                        leaveEarlyRecord.add(leaveEarlyfirstRecord);
                                    } else {
                                        status = "正常";
                                        normalfirst.setTime(DateFormat.getwyqStrTime(attend1.getAtime()));
                                        normalfirst.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        normalfirst.setDate(DateFormat.getDatestrTime(nowDate));
                                        normals.add(normalfirst);
                                    }
                                }
                            }
                        } else {
                            status = "未签到";
                            LackCard lackCardfirst = new LackCard();
                            LackCard lackCardfirstRecord = new LackCard();
                            lackCardfirst.setTime(attendSet.getAtime1());
                            lackCardfirst.setWeek(DateCompute.getWeekOfDate(nowDate));
                            lackCardfirst.setDate(DateFormat.getDatestrTime(nowDate));
                            lackCardfirstRecord.setTime(attendSet.getAtime1());
                            lackCardfirstRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                            lackCardfirstRecord.setDate(DateFormat.getDatestrTime(nowDate));
                            lackCards.add(lackCardfirst);
                            lackCardRecord.add(lackCardfirstRecord);
                        }
                    }
                    if (numberOne.equals(attendSet.getAtime2Setother())) {
                        String status = "";
                        Late latetwo = new Late();//迟到
                        Normal normaltwo = new Normal();//正常
                        LeaveEarly leaveEarlytwo = new LeaveEarly();//早退
                        Late latetwoRecord = new Late();//迟到
                        LeaveEarly leaveEarlytwoRecord = new LeaveEarly();//早退
                        Attend attend2 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowDate), uid, numberTwo);
                        if (attend2 != null) {
                            if (numberTwo.equals(attend2.getType())) {
                                if (numberOne.equals(attendSet.getCommute2())) {
                                    int a22 = DateFormat.getWYQTime(attendSet.getAtime2());
                                    if (this.reTime(attend2.getAtime()) > DateFormat.getWYQTime(attendSet.getAtime2())) {
                                        status = "迟到";
                                        latetwo.setTime(DateFormat.getwyqStrTime(attend2.getAtime()));
                                        latetwo.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        latetwo.setDate(DateFormat.getDatestrTime(nowDate));
                                        latetwo.setStr("迟到(" + DateFormat.parseMillisecone(this.reTime(attend2.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime2())) + ")");
                                        latetwo.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime2());
                                        latetwoRecord.setTime(DateFormat.getwyqStrTime(attend2.getAtime()));
                                        latetwoRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        latetwoRecord.setDate(DateFormat.getDatestrTime(nowDate));
                                        latetwoRecord.setStr("迟到(" + DateFormat.parseMillisecone(this.reTime(attend2.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime2())) + ")");
                                        latetwoRecord.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime2());
                                        lates.add(latetwo);
                                        lateRecord.add(latetwoRecord);
                                    } else {
                                        status = "正常";
                                        normaltwo.setTime(DateFormat.getwyqStrTime(attend2.getAtime()));
                                        normaltwo.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        normaltwo.setDate(DateFormat.getDatestrTime(nowDate));
                                        normals.add(normaltwo);
                                    }
                                } else {
                                    String a1 = DateFormat.getwyqStrTime(attend2.getAtime());
                                    if (this.reTime(attend2.getAtime()) < DateFormat.getWYQTime(attendSet.getAtime2())) {
                                        status = "早退";
                                        leaveEarlytwo.setTime(DateFormat.getwyqStrTime(attend2.getAtime()));
                                        leaveEarlytwo.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        leaveEarlytwo.setDate(DateFormat.getDatestrTime(nowDate));
                                        leaveEarlytwo.setStr("早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime2()) - this.reTime(attend2.getAtime())) + ")");
                                        leaveEarlytwo.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime2());
                                        leaveEarlytwoRecord.setTime(DateFormat.getwyqStrTime(attend2.getAtime()));
                                        leaveEarlytwoRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        leaveEarlytwoRecord.setDate(DateFormat.getDatestrTime(nowDate));
                                        leaveEarlytwoRecord.setStr("早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime2()) - this.reTime(attend2.getAtime())) + ")");
                                        leaveEarlytwoRecord.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime2());
                                        leaveEarlies.add(leaveEarlytwo);
                                        leaveEarlyRecord.add(leaveEarlytwoRecord);
                                    } else {
                                        status = "正常";
                                        normaltwo.setTime(DateFormat.getwyqStrTime(attend2.getAtime()));
                                        normaltwo.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        normaltwo.setDate(DateFormat.getDatestrTime(nowDate));
                                        normals.add(normaltwo);
                                    }
                                }
                            }
                        } else {
                            status = "未签到";
                            LackCard lackCardtwo = new LackCard();
                            LackCard lackCardtwoRecord = new LackCard();
                            lackCardtwo.setTime(attendSet.getAtime2());
                            lackCardtwo.setWeek(DateCompute.getWeekOfDate(nowDate));
                            lackCardtwo.setDate(DateFormat.getDatestrTime(nowDate));
                            lackCardtwoRecord.setTime(attendSet.getAtime2());
                            lackCardtwoRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                            lackCardtwoRecord.setDate(DateFormat.getDatestrTime(nowDate));
                            lackCards.add(lackCardtwo);
                            lackCardRecord.add(lackCardtwoRecord);
                        }
                    }
                    if (numberOne.equals(attendSet.getAtime3Setother())) {
                        String status = "";
                        Late latethree = new Late();//迟到
                        Normal normalthree = new Normal();//正常
                        LeaveEarly leaveEarlythree = new LeaveEarly();//早退
                        Late latethreeRecord = new Late();//迟到
                        LeaveEarly leaveEarlythreeRecord = new LeaveEarly();//早退
                        Attend attend3 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowDate), uid, numberThree);
                        if (attend3 != null) {
                            if (numberThree.equals(attend3.getType())) {
                                if (numberOne.equals(attendSet.getCommute3())) {
                                    String a1 = DateFormat.getwyqStrTime(attend3.getAtime());
                                    if (this.reTime(attend3.getAtime()) > DateFormat.getDateTimes(attendSet.getAtime3()).getTime()) {
                                        status = "迟到";
                                        latethree.setTime(DateFormat.getwyqStrTime(attend3.getAtime()));
                                        latethree.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        latethree.setDate(DateFormat.getDatestrTime(nowDate));
                                        latethree.setStr("迟到(" + DateFormat.parseMillisecone(this.reTime(attend3.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime3())) + ")");
                                        latethree.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime3());
                                        latethreeRecord.setTime(DateFormat.getwyqStrTime(attend3.getAtime()));
                                        latethreeRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        latethreeRecord.setDate(DateFormat.getDatestrTime(nowDate));
                                        latethreeRecord.setStr("迟到(" + DateFormat.parseMillisecone(this.reTime(attend3.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime3())) + ")");
                                        latethreeRecord.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime3());
                                        lates.add(latethree);
                                        lateRecord.add(latethreeRecord);
                                    } else {
                                        status = "正常";
                                        normalthree.setTime(DateFormat.getwyqStrTime(attend3.getAtime()));
                                        normalthree.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        normalthree.setDate(DateFormat.getDatestrTime(nowDate));
                                        normals.add(normalthree);
                                    }
                                } else {
                                    String a1 = DateFormat.getwyqStrTime(attend3.getAtime());
                                    if (this.reTime(attend3.getAtime()) < DateFormat.getDateTimes(attendSet.getAtime3()).getTime()) {
                                        status = "早退";
                                        leaveEarlythree.setTime(DateFormat.getwyqStrTime(attend3.getAtime()));
                                        leaveEarlythree.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        leaveEarlythree.setDate(DateFormat.getDatestrTime(nowDate));
                                        leaveEarlythree.setStr("早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime3()) - this.reTime(attend3.getAtime())) + ")");
                                        leaveEarlythree.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime3());
                                        leaveEarlythreeRecord.setTime(DateFormat.getwyqStrTime(attend3.getAtime()));
                                        leaveEarlythreeRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        leaveEarlythreeRecord.setDate(DateFormat.getDatestrTime(nowDate));
                                        leaveEarlythreeRecord.setStr("早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime3()) - this.reTime(attend3.getAtime())) + ")");
                                        leaveEarlythreeRecord.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime3());
                                        leaveEarlies.add(leaveEarlythree);
                                        leaveEarlyRecord.add(leaveEarlythreeRecord);
                                    } else {
                                        status = "正常";
                                        normalthree.setTime(DateFormat.getwyqStrTime(attend3.getAtime()));
                                        normalthree.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        normalthree.setDate(DateFormat.getDatestrTime(nowDate));
                                        normals.add(normalthree);
                                    }
                                }
                            }
                        } else {
                            status = "未签到";
                            LackCard lackCardthree = new LackCard();
                            LackCard lackCardthreeRecord = new LackCard();
                            lackCardthree.setTime(attendSet.getAtime3());
                            lackCardthree.setWeek(DateCompute.getWeekOfDate(nowDate));
                            lackCardthree.setDate(DateFormat.getDatestrTime(nowDate));
                            lackCardthreeRecord.setTime(attendSet.getAtime3());
                            lackCardthreeRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                            lackCardthreeRecord.setDate(DateFormat.getDatestrTime(nowDate));
                            lackCards.add(lackCardthree);
                            lackCardRecord.add(lackCardthreeRecord);
                        }
                    }
                    if (numberOne.equals(attendSet.getAtime4Setother())) {
                        String status = "";
                        Late latefour = new Late();//迟到
                        Normal normalfour = new Normal();//正常
                        LeaveEarly leaveEarlyfour = new LeaveEarly();//早退
                        LeaveEarly leaveEarlyfourRecord = new LeaveEarly();//早退
                        Late latefourRecord = new Late();//迟到
                        Attend attend4 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowDate), uid, numberFour);
                        if (attend4 != null) {
                            if (numberFour.equals(attend4.getType())) {
                                if (numberOne.equals(attendSet.getCommute4())) {
                                    String a1 = DateFormat.getwyqStrTime(attend4.getAtime());
                                    if (this.reTime(attend4.getAtime()) > DateFormat.getDateTimes(attendSet.getAtime4()).getTime()) {
                                        status = "迟到";
                                        latefour.setTime(DateFormat.getwyqStrTime(attend4.getAtime()));
                                        latefour.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        latefour.setDate(DateFormat.getDatestrTime(nowDate));
                                        latefour.setStr("迟到(" + DateFormat.parseMillisecone(this.reTime(attend4.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime4())) + ")");
                                        latefour.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime4());
                                        latefourRecord.setTime(DateFormat.getwyqStrTime(attend4.getAtime()));
                                        latefourRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        latefourRecord.setDate(DateFormat.getDatestrTime(nowDate));
                                        latefourRecord.setStr("迟到(" + DateFormat.parseMillisecone(this.reTime(attend4.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime4())) + ")");
                                        latefourRecord.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime4());
                                        lates.add(latefour);
                                        lateRecord.add(latefourRecord);
                                    } else {
                                        status = "正常";
                                        normalfour.setTime(DateFormat.getwyqStrTime(attend4.getAtime()));
                                        normalfour.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        normalfour.setDate(DateFormat.getDatestrTime(nowDate));
                                        normals.add(normalfour);
                                    }
                                } else {
                                    String a1 = DateFormat.getwyqStrTime(attend4.getAtime());
                                    if (this.reTime(attend4.getAtime()) < DateFormat.getDateTimes(attendSet.getAtime4()).getTime()) {
                                        status = "早退";
                                        leaveEarlyfour.setTime(DateFormat.getwyqStrTime(attend4.getAtime()));
                                        leaveEarlyfour.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        leaveEarlyfour.setDate(DateFormat.getDatestrTime(nowDate));
                                        leaveEarlyfour.setStr("早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime4()) - this.reTime(attend4.getAtime())) + ")");
                                        leaveEarlyfour.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime4());
                                        leaveEarlyfourRecord.setTime(DateFormat.getwyqStrTime(attend4.getAtime()));
                                        leaveEarlyfourRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        leaveEarlyfourRecord.setDate(DateFormat.getDatestrTime(nowDate));
                                        leaveEarlyfourRecord.setStr("早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime4()) - this.reTime(attend4.getAtime())) + ")");
                                        leaveEarlyfourRecord.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime4());
                                        leaveEarlies.add(leaveEarlyfour);
                                        leaveEarlyRecord.add(leaveEarlyfourRecord);
                                    } else {
                                        status = "正常";
                                        normalfour.setTime(DateFormat.getwyqStrTime(attend4.getAtime()));
                                        normalfour.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        normalfour.setDate(DateFormat.getDatestrTime(nowDate));
                                        normals.add(normalfour);
                                    }
                                }
                            }
                        } else {
                            status = "未签到";
                            LackCard lackCardfour = new LackCard();
                            LackCard lackCardfourRecord = new LackCard();
                            lackCardfour.setTime(attendSet.getAtime4());
                            lackCardfour.setWeek(DateCompute.getWeekOfDate(nowDate));
                            lackCardfour.setDate(DateFormat.getDatestrTime(nowDate));
                            lackCardfourRecord.setTime(attendSet.getAtime4());
                            lackCardfourRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                            lackCardfourRecord.setDate(DateFormat.getDatestrTime(nowDate));
                            lackCards.add(lackCardfour);
                            lackCardRecord.add(lackCardfourRecord);
                        }
                    }
                    if (numberOne.equals(attendSet.getAtime5Setother())) {
                        String status = "";
                        Late latefive = new Late();//迟到
                        Late latefiveRecord = new Late();//迟到
                        Normal normalfour = new Normal();//正常
                        LeaveEarly leaveEarlyfive = new LeaveEarly();//早退
                        LeaveEarly leaveEarlyfiveRecord = new LeaveEarly();//早退
                        Attend attend5 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowDate), uid, numberFive);
                        if (attend5 != null) {
                            if (numberFive.equals(attend5.getType())) {
                                if (numberOne.equals(attendSet.getCommute5())) {
                                    String a1 = DateFormat.getwyqStrTime(attend5.getAtime());
                                    if (this.reTime(attend5.getAtime()) > DateFormat.getDateTimes(attendSet.getAtime5()).getTime()) {
                                        status = "迟到";
                                        latefive.setTime(DateFormat.getwyqStrTime(attend5.getAtime()));
                                        latefive.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        latefive.setDate(DateFormat.getDatestrTime(nowDate));
                                        latefive.setStr("迟到(" + DateFormat.parseMillisecone(this.reTime(attend5.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime5())) + ")");
                                        latefive.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime5());
                                        latefiveRecord.setTime(DateFormat.getwyqStrTime(attend5.getAtime()));
                                        latefiveRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        latefiveRecord.setDate(DateFormat.getDatestrTime(nowDate));
                                        latefiveRecord.setStr("迟到(" + DateFormat.parseMillisecone(this.reTime(attend5.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime5())) + ")");
                                        latefiveRecord.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime5());
                                        lates.add(latefive);
                                        lateRecord.add(latefiveRecord);
                                    } else {
                                        status = "正常";
                                        normalfour.setTime(DateFormat.getwyqStrTime(attend5.getAtime()));
                                        normalfour.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        normalfour.setDate(DateFormat.getDatestrTime(nowDate));
                                        normals.add(normalfour);
                                    }
                                } else {
                                    String a1 = DateFormat.getwyqStrTime(attend5.getAtime());
                                    if (this.reTime(attend5.getAtime()) < DateFormat.getDateTimes(attendSet.getAtime5()).getTime()) {
                                        status = "早退";
                                        leaveEarlyfive.setTime(DateFormat.getwyqStrTime(attend5.getAtime()));
                                        leaveEarlyfive.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        leaveEarlyfive.setDate(DateFormat.getDatestrTime(nowDate));
                                        leaveEarlyfive.setStr("早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime5()) - this.reTime(attend5.getAtime())) + ")");
                                        leaveEarlyfive.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime5());
                                        leaveEarlyfiveRecord.setTime(DateFormat.getwyqStrTime(attend5.getAtime()));
                                        leaveEarlyfiveRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        leaveEarlyfiveRecord.setDate(DateFormat.getDatestrTime(nowDate));
                                        leaveEarlyfiveRecord.setStr("早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime5()) - this.reTime(attend5.getAtime())) + ")");
                                        leaveEarlyfiveRecord.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime5());
                                        leaveEarlies.add(leaveEarlyfive);
                                        leaveEarlyRecord.add(leaveEarlyfiveRecord);
                                    } else {
                                        status = "正常";
                                        normalfour.setTime(DateFormat.getwyqStrTime(attend5.getAtime()));
                                        normalfour.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        normalfour.setDate(DateFormat.getDatestrTime(nowDate));
                                        normals.add(normalfour);
                                    }
                                }
                            } else {
                                status = "未签到";
                                LackCard lackCardfive = new LackCard();
                                LackCard lackCardfiveRecord = new LackCard();
                                lackCardfive.setTime(attendSet.getAtime5());
                                lackCardfive.setWeek(DateCompute.getWeekOfDate(nowDate));
                                lackCardfive.setDate(DateFormat.getDatestrTime(nowDate));
                                lackCardfiveRecord.setTime(attendSet.getAtime5());
                                lackCardfiveRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                                lackCardfiveRecord.setDate(DateFormat.getDatestrTime(nowDate));
                                lackCards.add(lackCardfive);
                                lackCardRecord.add(lackCardfiveRecord);
                            }
                        }
                    }
                    if (numberOne.equals(attendSet.getAtime6Setother())) {
                        String status = "";
                        Late latesix = new Late();//迟到
                        Late latesixRecord = new Late();//迟到
                        Normal normalsix = new Normal();//正常
                        LeaveEarly leaveEarlysix = new LeaveEarly();//早退
                        LeaveEarly leaveEarlysixRecord = new LeaveEarly();//早退
                        Attend attend6 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowDate), uid, numberSix);
                        if (attend6 != null) {
                            if (numberSix.equals(attend6.getType())) {
                                if (numberOne.equals(attendSet.getCommute6())) {
                                    String a1 = DateFormat.getwyqStrTime(attend6.getAtime());
                                    if (this.reTime(attend6.getAtime()) > DateFormat.getDateTimes(attendSet.getAtime6()).getTime()) {
                                        status = "迟到";
                                        latesix.setTime(DateFormat.getwyqStrTime(attend6.getAtime()));
                                        latesix.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        latesix.setDate(DateFormat.getDatestrTime(nowDate));
                                        latesix.setStr("迟到(" + DateFormat.parseMillisecone(this.reTime(attend6.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime6())) + ")");
                                        latesix.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime6());
                                        latesixRecord.setTime(DateFormat.getwyqStrTime(attend6.getAtime()));
                                        latesixRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        latesixRecord.setDate(DateFormat.getDatestrTime(nowDate));
                                        latesixRecord.setStr("迟到(" + DateFormat.parseMillisecone(this.reTime(attend6.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime6())) + ")");
                                        latesixRecord.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime6());
                                        lates.add(latesix);
                                        lateRecord.add(latesixRecord);
                                    } else {
                                        status = "正常";
                                        normalsix.setTime(DateFormat.getwyqStrTime(attend6.getAtime()));
                                        normalsix.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        normalsix.setDate(DateFormat.getDatestrTime(nowDate));
                                        normals.add(normalsix);
                                    }
                                } else {
                                    String a1 = DateFormat.getwyqStrTime(attend6.getAtime());
                                    if (this.reTime(attend6.getAtime()) < DateFormat.getDateTimes(attendSet.getAtime6()).getTime()) {
                                        status = "早退";
                                        leaveEarlysix.setTime(DateFormat.getwyqStrTime(attend6.getAtime()));
                                        leaveEarlysix.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        leaveEarlysix.setDate(DateFormat.getDatestrTime(nowDate));
                                        leaveEarlysix.setStr("早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime6()) - this.reTime(attend6.getAtime())) + ")");
                                        leaveEarlysix.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime6());
                                        leaveEarlysixRecord.setTime(DateFormat.getwyqStrTime(attend6.getAtime()));
                                        leaveEarlysixRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        leaveEarlysixRecord.setDate(DateFormat.getDatestrTime(nowDate));
                                        leaveEarlysixRecord.setStr("早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime6()) - this.reTime(attend6.getAtime())) + ")");
                                        leaveEarlysixRecord.setAtime(DateFormat.getDatestr(nowDate) + "  " + attendSet.getAtime6());
                                        leaveEarlies.add(leaveEarlysix);
                                        leaveEarlyRecord.add(leaveEarlysixRecord);
                                    } else {
                                        status = "正常";
                                        normalsix.setTime(DateFormat.getwyqStrTime(attend6.getAtime()));
                                        normalsix.setWeek(DateCompute.getWeekOfDate(nowDate));
                                        normalsix.setDate(DateFormat.getDatestrTime(nowDate));
                                        normals.add(normalsix);
                                    }
                                }
                            } else {
                                status = "未签到";
                                LackCard lackCardsix = new LackCard();
                                LackCard lackCardsixRecord = new LackCard();
                                lackCardsix.setTime(attendSet.getAtime6());
                                lackCardsix.setWeek(DateCompute.getWeekOfDate(nowDate));
                                lackCardsix.setDate(DateFormat.getDatestrTime(nowDate));
                                lackCardsixRecord.setTime(attendSet.getAtime6());
                                lackCardsixRecord.setWeek(DateCompute.getWeekOfDate(nowDate));
                                lackCardsixRecord.setDate(DateFormat.getDatestrTime(nowDate));
                                lackCards.add(lackCardsix);
                                lackCardRecord.add(lackCardsixRecord);
                            }
                        }
                    }
                    //正常签到次数 大于等于 应签到次数
                    if (normals.size() >= xqhbt) {
                        normalNew.setWeek(DateCompute.getWeekOfDate(nowDate));
                        normalNew.setDate(DateFormat.getDatestrTime(nowDate));
                        normalNews.add(normalNew);
                    }
                    normals.clear();
                }
            }
            //异常签到记录
            List<Attend> attendListRet = new ArrayList<Attend>();
            Attend attendfirst = new Attend();
            attendfirst.setSname("迟到记录");
            attendfirst.setRemarksList(lateRecord);
            Attend attendtwo = new Attend();
            attendtwo.setSname("早退记录");
            attendtwo.setRemarksList(leaveEarlyRecord);
            Attend attendthree = new Attend();
            attendthree.setSname("缺卡记录");
            attendthree.setRemarksList(lackCardRecord);
            Attend attendfour = new Attend();
            attendfour.setSname("旷工记录");
            attendfour.setRemarksList(absenteeismRecord);
            attendListRet.add(attendfirst);
            attendListRet.add(attendtwo);
            attendListRet.add(attendthree);
            attendListRet.add(attendfour);
            //出勤天数
            Attend attend1 = new Attend();
            attend1.setSname("出勤天数");
            if (attendances.size() > 0) {
                attend1.setNum(attendances.size() + "");
                attend1.setState(numberOne);
            } else {
                attend1.setNum(numberZero);
                attend1.setState(numberZero);
            }
            attend1.setType("天");
            attend1.setRemarksList(attendances);
            //正常签到
            Attend attend2 = new Attend();
            attend2.setSname("正常签到");
            if (normalNews.size() > 0) {
                attend2.setNum(normalNews.size() + "");
                attend2.setState(numberOne);
            } else {
                attend2.setNum(numberZero);
                attend2.setState(numberZero);
            }
            attend2.setType("天");
            attend2.setRemarksList(normalNews);
            //外勤签到
            Attend attend3 = new Attend();
            attend3.setSname("外勤签到");
            if (fields.size() > 0) {
                attend3.setNum(fields.size() + "");
                attend3.setState(numberOne);
            } else {
                attend3.setNum(numberZero);
                attend3.setState(numberZero);
            }
            attend3.setType("次");
            attend3.setRemarksList(fields);
            Attend attend6 = new Attend();
            //迟到
            attend6.setSname("迟到");
            if (lates.size() > 0) {
                attend6.setNum(lates.size() + "");
                attend6.setState(numberOne);
            } else {
                attend6.setNum(numberZero);
                attend6.setState(numberZero);
            }
            attend6.setType("次");
            attend6.setRemarksList(lates);
            //早退
            Attend attend4 = new Attend();
            attend4.setSname("早退");
            if (leaveEarlies.size() > 0) {
                attend4.setNum(leaveEarlies.size() + "");
                attend4.setState(numberOne);
            } else {
                attend4.setNum(numberZero);
                attend4.setState(numberZero);
            }
            attend4.setType("次");
            attend4.setRemarksList(leaveEarlies);
            Attend attend5 = new Attend();
            attend5.setSname("缺卡");
            if (lackCards.size() > 0) {
                attend5.setNum(lackCards.size() + "");
                attend5.setState(numberOne);
            } else {
                attend5.setNum(numberZero);
                attend5.setState(numberZero);
            }
            attend5.setType("次");
            attend5.setRemarksList(lackCards);
            //旷工
            Attend attendAbsent = new Attend();
            attendAbsent.setSname("旷工");
            if (absenteeisms.size() > 0) {
                attendAbsent.setNum(absenteeisms.size() + "");
                attendAbsent.setState(numberOne);
            } else {
                attendAbsent.setNum(numberZero);
                attendAbsent.setState(numberZero);
            }
            attendAbsent.setType("天");
            attendAbsent.setRemarksList(absenteeisms);
            //设备异常
            Attend attendUnitExcep = new Attend();
            attendUnitExcep.setSname("设备异常");
            if (unitExceptionList.size() > 0) {
                attendUnitExcep.setNum(unitExceptionList.size() + "");
                attendUnitExcep.setState(numberOne);
            } else {
                attendUnitExcep.setNum(numberZero);
                attendUnitExcep.setState(numberZero);
            }
            attendUnitExcep.setType("次");
            attendUnitExcep.setRemarksList(unitExceptionList);
            //外出
            Attend goOut = new Attend();
            goOut.setSname("外出");
            if (attendOutList.size() > 0) {
                goOut.setNum(attendOutList.size() + "");
                goOut.setState(numberOne);
            } else {
                goOut.setNum(numberZero);
                goOut.setState(numberZero);
            }
            goOut.setType("次");
            goOut.setRemarksList(attendOutList);
            //请假
            Attend leave = new Attend();
            leave.setSname("请假");
            if (attendLeaveList.size() > 0) {
                leave.setNum(attendLeaveList.size() + "");
                leave.setState(numberOne);
            } else {
                leave.setNum(numberZero);
                leave.setState(numberZero);
            }
            leave.setType("次");
            leave.setRemarksList(attendLeaveList);
            //出差
            Attend evection = new Attend();
            evection.setSname("出差");
            if (attendEvectionList.size() > 0) {
                evection.setNum(attendEvectionList.size() + "");
                evection.setState(numberOne);
            } else {
                evection.setNum(numberZero);
                evection.setState(numberZero);
            }
            evection.setType("次");
            evection.setRemarksList(attendEvectionList);
            //加班
            Attend overtime = new Attend();
            overtime.setSname("加班");
            if (attendanceOvertimeList.size() > 0) {
                overtime.setNum(attendanceOvertimeList.size() + "");
                overtime.setState(numberOne);
            } else {
                overtime.setNum(numberZero);
                overtime.setState(numberZero);
            }
            overtime.setType("次");
            overtime.setRemarksList(attendanceOvertimeList);

            workList.add(attend1);
            workList.add(attend2);
            workList.add(attend3);
            workList.add(attend4);
            workList.add(attend5);
            workList.add(attend6);
            workList.add(attendAbsent);
            workList.add(attendUnitExcep);

            workList.add(goOut);
            workList.add(leave);
            workList.add(evection);
            workList.add(overtime);
            attend.setAttendList(workList);
            attend.setList(attendListRet);

            attend.setType("一个月的考勤类型");
            wrappers.setFlag(true);
            wrappers.setStatus(true);
            wrappers.setData(attend);
            wrappers.setMsg("更新成功");
        } catch (Exception e) {
            wrappers.setFlag(false);
            wrappers.setStatus(true);
            wrappers.setMsg("更新失败");
            e.printStackTrace();
        }
        return wrappers;
    }


    public BaseWrapper myAttend2(String date, String uid, String start, String end, HttpServletRequest req) throws ParseException {
        Cookie redisSessionId = CookiesUtil.getCookieByName(req, "redisSessionId");
        Users users = SessionUtils.getSessionInfo(req.getSession(), Users.class, new Users(), redisSessionId);
        Integer auid = users.getUid();
        Map<Integer, AttendSet> attendSetMap = new HashMap();
        List<BaseAttend> attendances = new ArrayList<BaseAttend>();//出勤
        List<BaseAttend> normals = new ArrayList<BaseAttend>();//正常判断
        List<BaseAttend> fields = new ArrayList<BaseAttend>();//外勤
        List<BaseAttend> leaveEarlies = new ArrayList<BaseAttend>();//早退
        List<BaseAttend> lackCards = new ArrayList<BaseAttend>();//缺卡
        List<BaseAttend> lates = new ArrayList<BaseAttend>();//迟到
        List<BaseAttend> absenteeisms = new ArrayList<BaseAttend>();//旷工
        List<BaseAttend> unitExceptions = new ArrayList<BaseAttend>();//设备异常
        List<BaseAttend> normalNews = new ArrayList<BaseAttend>();//正常
        List<BaseAttend> absenteeismRecord = new ArrayList<BaseAttend>();//旷工记录
        List<BaseAttend> leaveEarlyRecord = new ArrayList<BaseAttend>();//早退记录
        List<BaseAttend> lackCardRecord = new ArrayList<BaseAttend>();//缺卡记录
        List<BaseAttend> lateRecord = new ArrayList<BaseAttend>();//迟到记录
        List<BaseAttend> attendOutList = new ArrayList<BaseAttend>();//外出
        List<BaseAttend> attendanceOvertimeList = new ArrayList<BaseAttend>();//加班
        List<BaseAttend> attendEvectionList = new ArrayList<BaseAttend>();//出差
        List<BaseAttend> attendLeaveList = new ArrayList<BaseAttend>();//请假
        List<Attend> attendListFirst = new ArrayList<Attend>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Set<Date> datss = new HashSet<>();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
        SimpleDateFormat matter2 = new SimpleDateFormat("yyyy-MM-dd");
        Date dt = new Date();
        String a11 = df.format(dt);//获取当前日期
        String startDate = "";
        String endDate = "";
        if (start.equals(a11)) {
            startDate = start + "-01";
            endDate = matter2.format(dt);//获取当前日期时间
        } else {
            Date date1 = df.parse(start);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date1);
            int last1 = calendar.getActualMaximum(calendar.DAY_OF_MONTH);    //获取本月最大天数
            startDate = start + "-01";
            endDate = start + "-" + last1;
        }
        AttendSetWrappers wrappers = findAttendList3(null, null, startDate, endDate, null, null, auid, req, new HashMap<String, Object>());
        List<AttendTJ> attendTJList = (List<AttendTJ>) wrappers.getData();
        if (attendTJList != null && attendTJList.size() > 0) {
            String status = "";
            AttendTJ attendTJ = attendTJList.get(0);
            //获取出勤  1
            List<UserDuty> chuqinList = attendTJ.getShijichuqin();
            for (UserDuty userDuty : chuqinList) {
                Attendance attendance = new Attendance();//出勤
                attendance.setWeek(DateCompute.dateToWeek(userDuty.getDutyDate()));
                attendance.setDate(userDuty.getDutyDate());
                attendances.add(attendance);
            }
            Attend attend1 = setAttend("出勤天数", "天", attendances);

            //获取正常上班   2
            List<Attend> shangbanList = attendTJ.getShangbanList();
            for (Attend attend : shangbanList) {
                Normal normalNew = new Normal();
                normalNew.setWeek(DateCompute.dateToWeek(attend.getaTime()));
                normalNew.setDate(attend.getaTime());
                normalNews.add(normalNew);
            }
            Attend attend2 = setAttend("正常签到", "天", normalNews);

            //获取早退
            List<Attend> zaotuiList = attendTJ.getZaotuiList();
            for (Attend attend : zaotuiList) {
                status = "早退";
                LeaveEarly leaveEarlysix = new LeaveEarly();//早退
                leaveEarlysix.setTime(DateFormat.getwyqStrTime(attend.getAtime()));
                leaveEarlysix.setWeek(DateCompute.dateToWeek(attend.getaTime()));
                leaveEarlysix.setDate(attend.getaTime());
                leaveEarlysix.setStr("早退(" + (DateFormat.getTime(attend.getyTime()) - DateFormat.getTime(attend.getaTime())) + ")");
                leaveEarlysix.setAtime(attend.getyTime());
                LeaveEarly leaveEarlysixRecord = new LeaveEarly();//早退
                leaveEarlysixRecord.setTime(DateFormat.getwyqStrTime(attend.getAtime()));
                leaveEarlysixRecord.setWeek(DateCompute.dateToWeek(attend.getaTime()));
                leaveEarlysixRecord.setDate(attend.getaTime());
                leaveEarlysixRecord.setStr(leaveEarlysix.getStr());
                leaveEarlysixRecord.setAtime(leaveEarlysix.getAtime());
                leaveEarlies.add(leaveEarlysix);
                leaveEarlyRecord.add(leaveEarlysixRecord);
            }
            Attend attend4 = setAttend("早退", "次", leaveEarlies);
            //获取外勤
            List<Attend> waiqinList = attendTJ.getWaiqinList();
            for (Attend attend : waiqinList) {
                Field field = new Field();//外勤
                field.setDate(attend.getaTime());
                field.setTime(DateFormat.getwyqStrTime(attend.getAtime()));
                field.setStr(attend.getAddress());
                field.setPhoneId(attend.getPhoneId());
                field.setCause(attend.getRemark());
                fields.add(field);
            }
            Attend attend3 = setAttend("外勤签到", "次", fields);
            //获取未签到
            List<String> weiqiandaoList = attendTJ.getWeiqiandaoList();
            for (String time : weiqiandaoList) {
                status = "未签到";
                LackCard lackCardfirst = new LackCard();
                LackCard lackCardfirstRecord = new LackCard();
                lackCardfirst.setTime(time);
                lackCardfirst.setWeek(DateCompute.dateToWeek(time));
                lackCardfirst.setDate(time);
                lackCardfirstRecord.setTime(time);
                lackCardfirstRecord.setWeek(DateCompute.dateToWeek(time));
                lackCardfirstRecord.setDate(time);
                lackCards.add(lackCardfirst);
                lackCardRecord.add(lackCardfirstRecord);
            }
            Attend attend5 = setAttend("缺卡", "次", lackCardRecord);

            //获取迟到
            List<Attend> chidaoList = attendTJ.getChidaoList();
            for (Attend attend : chidaoList) {
                status = "迟到";
                Late latesix = new Late();//迟到
                latesix.setTime(DateFormat.getwyqStrTime(attend.getAtime()));
                latesix.setWeek(attend.getaTime());
                latesix.setDate(attend.getaTime());
                latesix.setStr("迟到(" + (DateFormat.getTime(attend.getaTime()) - DateFormat.getTime(attend.getyTime())) + ")");
                latesix.setAtime(attend.getyTime());
                Late latesixRecord = new Late();//迟到
                latesixRecord.setTime(latesix.getTime());
                latesixRecord.setWeek(latesix.getWeek());
                latesixRecord.setDate(latesix.getDate());
                latesixRecord.setStr(latesix.getStr());
                latesixRecord.setAtime(latesix.getAtime());
                lates.add(latesix);
                lateRecord.add(latesixRecord);
            }
            Attend attend6 = setAttend("迟到", "次", lates);
            //获取缺勤
            List<UserDuty> queqinList = (List<UserDuty>) attendTJ.getQueqinList();
            for (UserDuty userDuty : queqinList) {
                Absenteeism absenteeism = new Absenteeism();//缺勤
                Absenteeism absenteeismRecords = new Absenteeism();
                absenteeism.setWeek(DateCompute.dateToWeek(userDuty.getDutyDate()));
                absenteeism.setDate(userDuty.getDutyDate());
                absenteeismRecords.setWeek(DateCompute.dateToWeek(userDuty.getDutyDate()));
                absenteeismRecords.setDate(userDuty.getDutyDate());
                absenteeisms.add(absenteeism);
                absenteeismRecord.add(absenteeismRecords);
            }
            Attend attend7 = setAttend("旷工", "次", absenteeisms);
            //8  异常暂无
            Attend attend8 = setAttend("设备异常", "次", new ArrayList());

            Map<String, Object> map = new HashMap();
            map.put("userId", users.getUserId());
            map.put("beginDate", startDate);
            map.put("endDate", endDate);
            //查询请假
            List<AttendLeave> attendLeaves = attendLeaveMapper.getAttendLeaveListByMap(map);
            for (AttendLeave attendLeave : attendLeaves) {
                BaseAttend attendLeaveNew = new BaseAttend();
                attendLeaveNew.setStrat(DateFormat.getStrDate(attendLeave.getLeaveDate1()));
                attendLeaveNew.setEnd(DateFormat.getStrDate(attendLeave.getLeaveDate2()));
                attendLeaveNew.setStr("原因:" + attendLeave.getLeaveType());
                attendLeaveNew.setHour("1");
                attendLeaveList.add(attendLeaveNew);
            }
            Attend attend9 = setAttend("请假", "次", attendLeaveList);
            //查询加班
            List<Attend> jiabanList = attendTJ.getJiaban();
            for (Attend attend : jiabanList) {
                BaseAttend attendanceOvertimeNew = new BaseAttend();
                attendanceOvertimeNew.setStrat(DateFormat.getStrTime(attend.getAtime()));
                attendanceOvertimeNew.setEnd("");
                attendanceOvertimeNew.setStr("签到地点:" + attend.getAddress());
                attendanceOvertimeNew.setHour("");
                attendanceOvertimeList.add(attendanceOvertimeNew);
            }
//            List<AttendanceOvertime> attendanceOvertimes = attendanceOvertimeMapper.getAttendanceOvertimeListByMap(map);
//            for (AttendanceOvertime attendanceOvertime : attendanceOvertimes) {
//                BaseAttend attendanceOvertimeNew = new BaseAttend();
//                attendanceOvertimeNew.setStrat(DateFormat.getStrDate(attendanceOvertime.getStartTime()));
//                attendanceOvertimeNew.setEnd(DateFormat.getStrDate(attendanceOvertime.getEndTime()));
//                attendanceOvertimeNew.setStr("原因:" + attendanceOvertime.getReason());
//                attendanceOvertimeNew.setHour(attendanceOvertime.getOvertimeHours());
//                attendanceOvertimeList.add(attendanceOvertimeNew);
//            }
            Attend attend10 = setAttend("加班", "次", attendanceOvertimeList);
            //获取外出
            List<AttendOut> attendOuts = attendOutMapper.getAttendOutListByMap(map);
            for (AttendOut attendOut : attendOuts) {
                BaseAttend attendOutNew = new BaseAttend();
                attendOutNew.setStrat(attendOut.getOutTime1());
                attendOutNew.setEnd(attendOut.getOutTime2());
                attendOutNew.setStr("原因:" + attendOut.getOutType());
                attendOutNew.setHour("1");
                attendOutList.add(attendOutNew);
            }
            Attend attend11 = setAttend("外出", "次", attendOutList);
            //获取出差
            List<AttendEvection> attendEvections = attendEvectionMapper.getAttendEvectionListByMap(map);
            for (AttendEvection attendEvection : attendEvections) {
                BaseAttend attendEvectionNew = new BaseAttend();
                attendEvectionNew.setStrat(DateFormat.getStrDate(attendEvection.getEvectionDate1()));
                attendEvectionNew.setEnd(DateFormat.getStrDate(attendEvection.getEvectionDate2()));
                attendEvectionNew.setStr("原因:" + attendEvection.getReason());
                attendEvectionNew.setHour("1");
                attendEvectionList.add(attendEvectionNew);
            }
            Attend attend12 = setAttend("出差", "次", attendEvectionList);

            List<Attend> attendList = new ArrayList<Attend>();
            Attend attendfirst = new Attend();
            attendfirst.setSname("迟到记录");
            attendfirst.setRemarksList(lateRecord);
            Attend attendtwo = new Attend();
            attendtwo.setSname("早退记录");
            attendtwo.setRemarksList(leaveEarlyRecord);
            Attend attendthree = new Attend();
            attendthree.setSname("缺卡记录");
            attendthree.setRemarksList(lackCardRecord);
            Attend attendfour = new Attend();
            attendfour.setSname("旷工记录");
            attendfour.setRemarksList(absenteeismRecord);
            attendList.add(attendfirst);
            attendList.add(attendtwo);
            attendList.add(attendthree);
            attendList.add(attendfour);

            List<Attend> workList = new ArrayList<Attend>();
            workList.add(attend1);
            workList.add(attend2);
            workList.add(attend3);
            workList.add(attend4);
            workList.add(attend5);
            workList.add(attend6);
            workList.add(attend7);
            workList.add(attend8);
            workList.add(attend9);
            workList.add(attend10);
            workList.add(attend11);
            workList.add(attend12);
            Attend attend = new Attend();
            attend.setAttendList(workList);
            attend.setList(attendList);
            attend.setType("一个月的考勤类型");//attendSet.getTitle()
            wrappers.setFlag(true);
            wrappers.setStatus(true);
            wrappers.setData(attend);
            wrappers.setMsg("更新成功");
        }
        return wrappers;
    }

    /**
     * @创建作者:李然 Lr
     * @方法描述：公共设置attend方法
     * @创建时间：17:07 2019/5/16
     **/
    public Attend setAttend(String name, String type, List attendances) {
        Attend attend1 = new Attend();
        attend1.setSname(name);
        if (attendances.size() > 0) {
            attend1.setNum(attendances.size() + "");
            attend1.setState(numberOne);
        } else {
            attend1.setNum(numberZero);
            attend1.setState(numberZero);
        }
        attend1.setType(type);
        attend1.setRemarksList(attendances);
        return attend1;
    }

    //查询用户异常签到信息
    public List<BaseAttend> myAttendUnitException(String start, String end, Integer uid, HttpServletRequest request) {
        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionId);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("strat", start);
        map.put("end", end);
        map.put("uid", uid);
        List<Attend> attendList = attendMapper.queryCountPhone(map);
        List<Integer> attendList1 = new ArrayList<Integer>();
        List<BaseAttend> unitExceptionList = new ArrayList<BaseAttend>();

        Attend attendNew = new Attend();
        for (Attend attend1 : attendList) {
            attendList1.add(attend1.getCount());
        }
        if (attendList1 != null && attendList1.size() > 0) {
            Integer integer = Collections.max(attendList1);
            int i = integer.intValue();
            double b = i * 0.3;
            for (Attend attend1 : attendList) {
                if (b >= attend1.getCount()) {
                    String phone = attend1.getPhoneId();
                    Map<String, Object> maps = new HashMap<String, Object>();
                    maps.put("phone", phone);
                    maps.put("strat", start);
                    maps.put("end", end);
                    List<Attend> attendList2 = attendMapper.queryAttendPhone(maps);
                    for (Attend attend11 : attendList2) {
                        UnitException unitException = new UnitException();
                        unitException.setDate(DateFormat.getDatestrTime(attend11.getDate()));
                        unitException.setTime(DateFormat.getwyqStrTime(attend11.getAtime()));
                        unitException.setPhoneId(attend11.getPhoneId());
                        unitException.setAtime(DateFormat.getDatestrTime(attend11.getDate()) + "    " + DateFormat.getwyqStrTime(attend11.getAtime()));
                        Map<String, Object> map1 = new HashMap<String, Object>();
                        String msg = "";
                        if (!users.getUid().equals(attend11.getUid())) {
                            String name = usersMapper.getUsernameById(attend11.getUid());
                            msg = "疑似" + name + "代签";
                        } else {
                            msg = "新设备" + phone;
                        }
                        unitException.setStr(msg);
                        unitExceptionList.add(unitException);
                    }
                }
            }
        }
        return unitExceptionList;
    }

    //查询用户本月的签到 （日期为当前日期的话查 本月1号到当天----日期不为当前日期的话，查询整月的签到情况）
    //判断用户===代签
    public String companyAttendanceException(String date, Integer uid, String type) throws ParseException {
        String date1[] = date.split("-");
        String start = date1[0] + "-" + date1[1];
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
        SimpleDateFormat matter2 = new SimpleDateFormat("yyyy-MM-dd");
        Date dt = new Date();
        String a11 = df.format(dt);//获取当前日期
        String stratDate = "";
        String endDate = "";
        if (start.equals(a11)) {
            stratDate = date + "-01";
            endDate = matter2.format(dt);//获取当前日期时间
        } else {
            Date date2 = df.parse(start);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date2);
            int first1 = calendar.getActualMinimum(calendar.DAY_OF_MONTH);    //获取本月最小天数
            int last1 = calendar.getActualMaximum(calendar.DAY_OF_MONTH);    //获取本月最大天数
            stratDate = start + "-01";
            endDate = start + "-" + last1;
        }

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("strat", stratDate);
        map.put("end", endDate);
        map.put("uid", uid);
        List<Attend> attendList = attendMapper.queryCountPhone(map);
        List<Integer> attendList1 = new ArrayList<Integer>();

        for (Attend attend1 : attendList) {
            attendList1.add(attend1.getCount());
            Integer a1 = attend1.getCount();
        }
        if (attendList1 != null && attendList1.size() > 0) {
            Integer integer = Collections.max(attendList1);
            int i = integer.intValue();
            double b = i * 0.3;
            for (Attend attend1 : attendList) {
                if (b < attend1.getCount()) {

                } else {

                    String phone = attend1.getPhoneId();
                    Map<String, Object> maps = new HashMap<String, Object>();
                    maps.put("phone", phone);
                    maps.put("date", date);
                    maps.put("type", type);

                    List<Attend> attendListNew = attendMapper.queryAttendPhoneId(maps);
                    Iterator<Attend> attendIterator = attendListNew.iterator();
                    while (attendIterator.hasNext()) {
                        Attend attend = attendIterator.next();
                        if (attend != null) {
                            String msg = "";
                            if (!uid.equals(attend.getUid().toString())) {
                                String name = usersMapper.getUsernameById(attend.getUid());
                                msg = "疑似" + name + "代签";
                            } else {
                                msg = "新设备" + phone;
                            }

                            return msg;
                        } else {
                            return null;
                        }
                    }

                }
            }
        }
        return null;


    }

    //情况统计
    public BaseWrapper companyAttendance(String date) {
        AttendSetWrappers wrappers = new AttendSetWrappers();

        try {
            Map<String, Object> maps = new HashMap<String, Object>();
            List<Users> usersList = usersMapper.getAlluser(maps);
            Iterator<Users> usersIterator = usersList.iterator();
            List<BaseSupplement> normal = new ArrayList<BaseSupplement>();//上班正常
            List<BaseSupplement> normalyichang = new ArrayList<BaseSupplement>();//上班异常
            List<BaseSupplement> closed = new ArrayList<BaseSupplement>();//下班正常
            List<BaseSupplement> closedyichang = new ArrayList<BaseSupplement>();//下班异常
            List<BaseSupplement> notSign = new ArrayList<BaseSupplement>();//未签到
            List<BaseSupplement> notOut = new ArrayList<BaseSupplement>();//未签退
            List<BaseSupplement> leaveEarly = new ArrayList<BaseSupplement>();//早退
            List<BaseSupplement> late = new ArrayList<BaseSupplement>();//迟到
            List<BaseSupplement> filds = new ArrayList<BaseSupplement>();//waiqin
            List<BaseSupplement> notSignNumbers = new ArrayList<BaseSupplement>();//未签到
            List<BaseSupplement> notOutNumbers = new ArrayList<BaseSupplement>();//未签退
            List<BaseSupplement> leaveEarlyNumbers = new ArrayList<BaseSupplement>();//早退
            List<BaseSupplement> lateNumbers = new ArrayList<BaseSupplement>();//迟到

            List<BaseSupplement> leaves = new ArrayList<BaseSupplement>();//waiqin
            List<BaseSupplement> waichu = new ArrayList<BaseSupplement>();//waiqin
            List<BaseSupplement> chucha = new ArrayList<BaseSupplement>();//waiqin

            int chuqinRenshu = 0;
            while (usersIterator.hasNext()) {
                Users users = usersIterator.next();
                BaseSupplement normalB = new BaseSupplement();
                BaseSupplement normalyichangB = new BaseSupplement();
                BaseSupplement closedB = new BaseSupplement();
                BaseSupplement closedyichangB = new BaseSupplement();
                BaseSupplement lateNumber = new BaseSupplement();
                BaseSupplement leaveEarlyNumber = new BaseSupplement();
                BaseSupplement notSignNumber = new BaseSupplement();
                BaseSupplement notOutNumber = new BaseSupplement();
                Integer uid = users.getUid();
                Map<String, Object> mapss = new HashMap<>();
                mapss.put("uid", uid);
                mapss.put("date", date);

                Date dateTime = new Date();
                SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
                String time = format.format(dateTime);
                Date dateTime1 = new Date();
                SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
                String time1 = format1.format(dateTime1);
                AttendSet attendSet = null;
                UserDuty userDuty = userDutyMapper.userDuty(uid, date);
                if (userDuty != null) {
                    attendSet = attendSetMapper.selectAttendSetSid(userDuty.getDutyType());
                    if (attendSet != null) {
                        String[] str1 = attendSet.getAtime1Set().split("\\|");
                        attendSet.setAtime1Setother(str1[0]);
                        attendSet.setCommute1(str1[1]);
                        String[] str2 = attendSet.getAtime2Set().split("\\|");
                        attendSet.setAtime2Setother(str2[0]);
                        attendSet.setCommute2(str2[1]);
                        String[] str3 = attendSet.getAtime3Set().split("\\|");
                        attendSet.setAtime3Setother(str3[0]);
                        attendSet.setCommute3(str3[1]);
                        String[] str4 = attendSet.getAtime4Set().split("\\|");
                        attendSet.setAtime4Setother(str4[0]);
                        attendSet.setCommute4(str4[1]);
                        String[] str5 = attendSet.getAtime5Set().split("\\|");
                        attendSet.setAtime5Setother(str5[0]);
                        attendSet.setCommute5(str5[1]);
                        String[] str6 = attendSet.getAtime6Set().split("\\|");
                        attendSet.setAtime6Setother(str6[0]);
                        attendSet.setCommute6(str6[1]);

                        if (numberOne.equals(attendSet.getIsOut())) {
                            List<Attend> attendList = new ArrayList<Attend>();
                            List<Attend> attend0 = attendMapper.selectAttend0(date, uid);
                            if (attend0 != null && attend0.size() > 0) {
                                BaseSupplement fild = new BaseSupplement();
                                fild.setUid(uid);
                                fild.setName(users.getName());
                                fild.setAvatar(users.getAvatar());
                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                    Department department = departmentMapper.getDeptById(users.getDeptId());

                                    fild.setDept(department.getDeptName());
                                } else {
                                    fild.setDept("未指定部门");

                                }

                                fild.setStr(attend0.size() + "次外勤记录");
                                Iterator<Attend> attendIterator = attend0.iterator();
                                while (attendIterator.hasNext()) {
                                    Attend attend = attendIterator.next();
                                    Attend attendwaiqin = new Attend();
                                    attendwaiqin.setTime(DateFormat.getwyqStrTime(attend.getAtime()));
                                    String[] a2 = attend.getAddress().split(",");
                                    attendwaiqin.setAddress(a2[a2.length - 1]);
                                    attendList.add(attendwaiqin);
                                }
                                fild.setCishu(attendList);
                                filds.add(fild);
                            }

                        }

                        List<AttendLeave> attendLeaveList = attendLeaveMapper.selectAttendLeaveModify(users.getUserId(), date);
                        if (attendLeaveList.size() > 0 && attendLeaveList != null) {
                            Iterator<AttendLeave> attendIterator = attendLeaveList.iterator();
                            while (attendIterator.hasNext()) {
                                AttendLeave attendLeave = attendIterator.next();
                                BaseSupplement attendLeaveqingjia = new BaseSupplement();
                                attendLeaveqingjia.setUid(uid);
                                attendLeaveqingjia.setName(users.getName());
                                attendLeaveqingjia.setAvatar(users.getAvatar());
                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                    Department department = departmentMapper.getDeptById(users.getDeptId());

                                    attendLeaveqingjia.setDept(department.getDeptName());
                                } else {
                                    attendLeaveqingjia.setDept("未指定部门");

                                }
                                attendLeaveqingjia.setStr(DateFormat.getStrDate(attendLeave.getLeaveDate1()) + "至" + DateFormat.getStrDate(attendLeave.getLeaveDate2()));
                                attendLeaveqingjia.setContent("原因:" + attendLeave.getLeaveType());
                                attendLeaveqingjia.setFlag(attendLeave.getLeaveType2());
                                leaves.add(attendLeaveqingjia);
                            }
                        }
                        List<AttendOut> attendOutList = attendOutMapper.queryAttendOut(users.getUserId(), date);
                        if (attendOutList.size() > 0 && attendOutList != null) {
                            Iterator<AttendOut> attendOutIterator = attendOutList.iterator();
                            while (attendOutIterator.hasNext()) {
                                AttendOut attendOut = attendOutIterator.next();
                                BaseSupplement attendOutwaichu = new BaseSupplement();
                                attendOutwaichu.setUid(uid);
                                attendOutwaichu.setName(users.getName());
                                attendOutwaichu.setAvatar(users.getAvatar());
                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                    Department department = departmentMapper.getDeptById(users.getDeptId());

                                    attendOutwaichu.setDept(department.getDeptName());
                                } else {
                                    attendOutwaichu.setDept("未指定部门");

                                }
                                attendOutwaichu.setStr(attendOut.getOutTime1() + "至" + attendOut.getOutTime2());
                                attendOutwaichu.setContent("原因:" + attendOut.getOutType());
                                attendOutwaichu.setFlag(attendOut.getStatus());

                                waichu.add(attendOutwaichu);
                            }
                        }
                        List<AttendEvection> attendEvections = attendEvectionMapper.selectAttendEvectionModify(users.getUserId(), date);
                        if (attendEvections.size() > 0 && attendEvections != null) {
                            Iterator<AttendEvection> attendEvectionIterator = attendEvections.iterator();

                            while (attendEvectionIterator.hasNext()) {
                                AttendEvection attendEvection = attendEvectionIterator.next();
                                BaseSupplement attendEvectionchucha = new BaseSupplement();
                                attendEvectionchucha.setUid(uid);
                                attendEvectionchucha.setName(users.getName());
                                attendEvectionchucha.setAvatar(users.getAvatar());
                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                    Department department = departmentMapper.getDeptById(users.getDeptId());

                                    attendEvectionchucha.setDept(department.getDeptName());
                                } else {
                                    attendEvectionchucha.setDept("未指定部门");

                                }

                                attendEvectionchucha.setStr(DateFormat.getStrDate(attendEvection.getEvectionDate1()) + "至" + DateFormat.getStrDate(attendEvection.getEvectionDate2()));
                                attendEvectionchucha.setContent("原因:" + attendEvection.getReason() + "地点" + attendEvection.getEvectionDest());
                                attendEvectionchucha.setFlag(attendEvection.getStatus());
                                chucha.add(attendEvectionchucha);
                            }
                        }

                        Map<String, Object> chuqinmap = new HashMap<String, Object>();
                        chuqinmap.put("uid", uid);
                        chuqinmap.put("date", date);
                        List<Attend> attendList111 = attendMapper.selectAttendList(chuqinmap);
                        if (attendList111 != null && attendList111.size() > 0) {
                            chuqinRenshu++;
                        }


                        if (numberOne.equals(attendSet.getAtime1Setother())) {
                            if (DateFormat.getDateTimes(attendSet.getAtime1()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {
                                String status = "";
                                if (numberOne.equals(attendSet.getCommute1())) {
                                    Attend attend1 = attendMapper.selectAttendAll(date, uid, numberOne);
                                    if (attend1 != null) {
                                        String a1 = DateFormat.getwyqStrTime(attend1.getAtime());
                                        if (this.reTime(attend1.getAtime()) > DateFormat.getDateTimes(attendSet.getAtime1()).getTime()) {
                                            status = "迟到";
                                            BaseSupplement latefirst = new BaseSupplement();
                                            latefirst.setUid(uid);
                                            latefirst.setName(users.getName());
                                            latefirst.setAvatar(users.getAvatar());
                                            if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                Department department = departmentMapper.getDeptById(users.getDeptId());
                                                latefirst.setDept(department.getDeptName());
                                            } else {
                                                latefirst.setDept("未指定部门");

                                            }

                                            latefirst.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend1.getAtime()) + "迟到(" + DateFormat.parseMillisecone(this.reTime(attend1.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime1())) + ")");

                                            lateNumber.setStr("签到时间为：" + attendSet.getAtime1() + DateFormat.getwyqStrTime(attend1.getAtime()) + DateFormat.getwyqStrTime(attend1.getAtime() - DateFormat.getWYQTime(attendSet.getAtime1())));

                                            late.add(latefirst);

                                        } else {
                                            status = "正常";
                                            String msg = companyAttendanceException(date, uid, numberOne);
                                            if (!StringUtils.checkNull(msg)) {
                                                normalyichangB.setUid(uid);
                                                normalyichangB.setName(users.getName());
                                                normalyichangB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    normalyichangB.setDept(department.getDeptName());
                                                } else {
                                                    normalyichangB.setDept("未指定部门");

                                                }
                                                normalyichangB.setStr(msg);

                                            } else {
                                                normalB.setUid(uid);
                                                normalB.setName(users.getName());
                                                normalB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    normalB.setDept(department.getDeptName());
                                                } else {
                                                    normalB.setDept("未指定部门");

                                                }

                                                normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend1.getAtime()));

                                            }


                                        }
                                    } else {
                                        status = "未签到";
                                        BaseSupplement notSignfirst = new BaseSupplement();
                                        notSignfirst.setUid(uid);
                                        notSignfirst.setName(users.getName());
                                        notSignfirst.setAvatar(users.getAvatar());
                                        if (users.getDeptId() != null && users.getDeptId() != 0) {
                                            Department department = departmentMapper.getDeptById(users.getDeptId());

                                            notSignfirst.setDept(department.getDeptName());
                                        } else {
                                            notSignfirst.setDept("未指定部门");
                                        }
                                        notSignfirst.setStr("未签到(规定签到时间为：" + attendSet.getAtime1() + ")");
                                        notSignNumber.setStr("签到时间为：" + attendSet.getAtime1());
                                        notSign.add(notSignfirst);


                                    }
                                } else {
                                    Attend attend1 = attendMapper.selectAttendAll(date, uid, numberOne);
                                    if (attend1 != null) {
                                        String a1 = DateFormat.getwyqStrTime(attend1.getAtime());
                                        if (this.reTime(attend1.getAtime()) < DateFormat.getDateTimes(attendSet.getAtime1()).getTime()) {
                                            status = "早退";
                                            BaseSupplement leaveEarlyfirst = new BaseSupplement();
                                            leaveEarlyfirst.setUid(uid);
                                            leaveEarlyfirst.setName(users.getName());
                                            leaveEarlyfirst.setAvatar(users.getAvatar());
                                            if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                Department department = departmentMapper.getDeptById(users.getDeptId());

                                                leaveEarlyfirst.setDept(department.getDeptName());
                                            } else {
                                                leaveEarlyfirst.setDept("未指定部门");
                                            }
                                            leaveEarlyfirst.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend1.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime1()) - attend1.getAtime()) + ")");
                                            leaveEarlyNumber.setStr("签到时间为：" + attendSet.getAtime1());
                                            leaveEarly.add(leaveEarlyfirst);

                                        } else {
                                            String msg = companyAttendanceException(date, uid, numberOne);
                                            if (!StringUtils.checkNull(msg)) {
                                                closedyichangB.setUid(uid);
                                                closedyichangB.setName(users.getName());
                                                closedyichangB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    closedyichangB.setDept(department.getDeptName());
                                                } else {
                                                    closedyichangB.setDept("未指定部门");

                                                }
                                                closedyichangB.setStr(msg);

                                            } else {
                                                closedB.setUid(uid);
                                                closedB.setName(users.getName());
                                                closedB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    closedB.setDept(department.getDeptName());
                                                } else {
                                                    closedB.setDept("未指定部门");

                                                }

                                                closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend1.getAtime()));

                                            }
                                        }
                                    } else {
                                        status = "未签到";
                                        BaseSupplement notOutfirst = new BaseSupplement();
                                        notOutfirst.setUid(uid);
                                        notOutfirst.setName(users.getName());
                                        notOutfirst.setAvatar(users.getAvatar());
                                        if (users.getDeptId() != null && users.getDeptId() != 0) {
                                            Department department = departmentMapper.getDeptById(users.getDeptId());

                                            notOutfirst.setDept(department.getDeptName());
                                        } else {
                                            notOutfirst.setDept("未指定部门");
                                        }
                                        notOutfirst.setStr("未签退(规定签到时间为：" + attendSet.getAtime1() + ")");
                                        notOutNumber.setStr("签到时间为：" + attendSet.getAtime1());
                                        notOut.add(notOutfirst);

                                    }
                                }
                            }
                        }

                        if (numberOne.equals(attendSet.getAtime2Setother())) {
                            if (DateFormat.getDateTimes(attendSet.getAtime2()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {
                                String status = "";
                                if (numberOne.equals(attendSet.getCommute2())) {
                                    Attend attend2 = attendMapper.selectAttendAll(date, uid, numberTwo);
                                    if (attend2 != null) {
                                        int a22 = DateFormat.getWYQTime(attendSet.getAtime2());
                                        if (this.reTime(attend2.getAtime()) > DateFormat.getWYQTime(attendSet.getAtime2())) {
                                            status = "迟到";
                                            BaseSupplement latetwo = new BaseSupplement();
                                            latetwo.setUid(uid);
                                            latetwo.setName(users.getName());
                                            latetwo.setAvatar(users.getAvatar());
                                            if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                Department department = departmentMapper.getDeptById(users.getDeptId());

                                                latetwo.setDept(department.getDeptName());
                                            } else {
                                                latetwo.setDept("未指定部门");
                                            }
                                            Long res = null;
                                            if (attend2.getAtime().toString().contains("000")) {
                                                res = Long.valueOf(attend2.getAtime());
                                            } else {
                                                res = Long.valueOf(attend2.getAtime() * 1000L);


                                            }


                                            latetwo.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend2.getAtime()) + "迟到(" + DateFormat.parseMillisecone(this.reTime(attend2.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime2())) + ")");
                                            lateNumber.setStr("签到时间为：" + attendSet.getAtime2());

                                            late.add(latetwo);
                                        } else {
                                            status = "正常";
                                            String msg = companyAttendanceException(date, uid, numberTwo);
                                            if (!StringUtils.checkNull(msg)) {
                                                normalyichangB.setUid(uid);
                                                normalyichangB.setName(users.getName());
                                                normalyichangB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    normalyichangB.setDept(department.getDeptName());
                                                } else {
                                                    normalyichangB.setDept("未指定部门");

                                                }
                                                normalyichangB.setStr(msg);

                                            } else {
                                                normalB.setUid(uid);
                                                normalB.setName(users.getName());
                                                normalB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    normalB.setDept(department.getDeptName());
                                                } else {
                                                    normalB.setDept("未指定部门");

                                                }

                                                normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend2.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);

                                            }
                                        }
                                    } else {
                                        status = "未签到";
                                        BaseSupplement notSigntwo = new BaseSupplement();
                                        notSigntwo.setUid(uid);
                                        notSigntwo.setName(users.getName());
                                        notSigntwo.setAvatar(users.getAvatar());
                                        if (users.getDeptId() != null && users.getDeptId() != 0) {
                                            Department department = departmentMapper.getDeptById(users.getDeptId());

                                            notSigntwo.setDept(department.getDeptName());
                                        } else {
                                            notSigntwo.setDept("未指定部门");
                                        }
                                        notSigntwo.setStr("未签到(规定签到时间为：" + attendSet.getAtime1() + ")");
                                        notSignNumber.setStr("签到时间为：" + attendSet.getAtime2());
                                        notSign.add(notSigntwo);
                                    }
                                } else {
                                    Attend attend2 = attendMapper.selectAttendAll(date, uid, numberTwo);
                                    if (attend2 != null) {


                                        String a1 = DateFormat.getwyqStrTime(attend2.getAtime());
                                        if (this.reTime(attend2.getAtime()) < DateFormat.getWYQTime(attendSet.getAtime2())) {
                                            status = "早退";
                                            BaseSupplement leaveEarlytwo = new BaseSupplement();
                                            leaveEarlytwo.setUid(uid);
                                            leaveEarlytwo.setName(users.getName());
                                            leaveEarlytwo.setAvatar(users.getAvatar());
                                            if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                Department department = departmentMapper.getDeptById(users.getDeptId());

                                                leaveEarlytwo.setDept(department.getDeptName());
                                            } else {
                                                leaveEarlytwo.setDept("未指定部门");
                                            }
                                            leaveEarlytwo.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend2.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime2()) - attend2.getAtime()) + ")");
                                            leaveEarlyNumber.setStr("签到时间为：" + attendSet.getAtime2());
                                            leaveEarly.add(leaveEarlytwo);
                                        } else {
                                            status = "正常";
                                            String msg = companyAttendanceException(date, uid, numberTwo);
                                            if (!StringUtils.checkNull(msg)) {
                                                closedyichangB.setUid(uid);
                                                closedyichangB.setName(users.getName());
                                                closedyichangB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    closedyichangB.setDept(department.getDeptName());
                                                } else {
                                                    closedyichangB.setDept("未指定部门");

                                                }
                                                closedyichangB.setStr(msg);

                                            } else {
                                                closedB.setUid(uid);
                                                closedB.setName(users.getName());
                                                closedB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    closedB.setDept(department.getDeptName());
                                                } else {
                                                    closedB.setDept("未指定部门");

                                                }

                                                closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend2.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);

                                            }
                                        }
                                    } else {
                                        status = "未签到";
                                        BaseSupplement notOuttwo = new BaseSupplement();
                                        notOuttwo.setUid(uid);
                                        notOuttwo.setName(users.getName());
                                        notOuttwo.setAvatar(users.getAvatar());
                                        if (users.getDeptId() != null && users.getDeptId() != 0) {
                                            Department department = departmentMapper.getDeptById(users.getDeptId());

                                            notOuttwo.setDept(department.getDeptName());
                                        } else {
                                            notOuttwo.setDept("未指定部门");
                                        }
                                        notOuttwo.setStr("未签退(规定签到时间为：" + attendSet.getAtime2() + ")");/*+"迟到"+DateFormat.getwyqStrTime(i2)*/
                                        notOutNumber.setStr("签到时间为：" + attendSet.getAtime2());
                                        notOut.add(notOuttwo);
                                    }


                                }
                            }

                        }
                        if (numberOne.equals(attendSet.getAtime3Setother())) {
                            if (DateFormat.getDateTimes(attendSet.getAtime3()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {
                                String status = "";
                                if (numberOne.equals(attendSet.getCommute3())) {
                                    Attend attend3 = attendMapper.selectAttendAll(date, uid, numberThree);
                                    if (attend3 != null) {
                                        String a1 = DateFormat.getwyqStrTime(attend3.getAtime());
                                        if (this.reTime(attend3.getAtime()) > DateFormat.getDateTimes(attendSet.getAtime3()).getTime()) {
                                            status = "迟到";
                                            BaseSupplement latethree = new BaseSupplement();
                                            latethree.setUid(uid);
                                            latethree.setName(users.getName());
                                            latethree.setAvatar(users.getAvatar());
                                            if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                Department department = departmentMapper.getDeptById(users.getDeptId());

                                                latethree.setDept(department.getDeptName());
                                            } else {
                                                latethree.setDept("未指定部门");
                                            }
                                            latethree.setStr("签到时间为：" + attendSet.getAtime3() + "迟到(" + DateFormat.parseMillisecone(this.reTime(attend3.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime3())) + ")");
                                            lateNumber.setStr("签到时间为：" + attendSet.getAtime3());

                                            late.add(latethree);
                                        } else {
                                            status = "正常";
                                            String msg = companyAttendanceException(date, uid, numberThree);
                                            if (!StringUtils.checkNull(msg)) {
                                                normalyichangB.setUid(uid);
                                                normalyichangB.setName(users.getName());
                                                normalyichangB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    normalyichangB.setDept(department.getDeptName());
                                                } else {
                                                    normalyichangB.setDept("未指定部门");

                                                }
                                                normalyichangB.setStr(msg);

                                            } else {
                                                normalB.setUid(uid);
                                                normalB.setName(users.getName());
                                                normalB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    normalB.setDept(department.getDeptName());
                                                } else {
                                                    normalB.setDept("未指定部门");

                                                }

                                                normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend3.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);

                                            }
                                        }
                                    } else {
                                        status = "weiqiandao";
                                        BaseSupplement notSignthree = new BaseSupplement();
                                        notSignthree.setUid(uid);
                                        notSignthree.setName(users.getName());
                                        notSignthree.setAvatar(users.getAvatar());
                                        if (users.getDeptId() != null && users.getDeptId() != 0) {
                                            Department department = departmentMapper.getDeptById(users.getDeptId());

                                            notSignthree.setDept(department.getDeptName());
                                        } else {
                                            notSignthree.setDept("未指定部门");
                                        }
                                        notSignthree.setStr("未签到(规定签到时间为：" + attendSet.getAtime3() + ")");
                                        notSignNumber.setStr("签到时间为：" + attendSet.getAtime3());
                                        notSign.add(notSignthree);
                                    }
                                } else {
                                    Attend attend3 = attendMapper.selectAttendAll(date, uid, numberThree);
                                    if (attend3 != null) {
                                        String a1 = DateFormat.getwyqStrTime(attend3.getAtime());
                                        if (this.reTime(attend3.getAtime()) < DateFormat.getDateTimes(attendSet.getAtime3()).getTime()) {
                                            status = "早退";
                                            BaseSupplement leaveEarlythree = new BaseSupplement();
                                            leaveEarlythree.setUid(uid);
                                            leaveEarlythree.setName(users.getName());
                                            leaveEarlythree.setAvatar(users.getAvatar());
                                            if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                Department department = departmentMapper.getDeptById(users.getDeptId());

                                                leaveEarlythree.setDept(department.getDeptName());
                                            } else {
                                                leaveEarlythree.setDept("未指定部门");
                                            }
                                            leaveEarlythree.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend3.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime3()) - attend3.getAtime()) + ")");
                                            leaveEarlyNumber.setStr("签到时间为：" + attendSet.getAtime3());
                                            leaveEarly.add(leaveEarlythree);
                                        } else {
                                            status = "正常";
                                            String msg = companyAttendanceException(date, uid, numberThree);
                                            if (!StringUtils.checkNull(msg)) {
                                                closedyichangB.setUid(uid);
                                                closedyichangB.setName(users.getName());
                                                closedyichangB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    closedyichangB.setDept(department.getDeptName());
                                                } else {
                                                    closedyichangB.setDept("未指定部门");

                                                }
                                                closedyichangB.setStr(msg);

                                            } else {
                                                closedB.setUid(uid);
                                                closedB.setName(users.getName());
                                                closedB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    closedB.setDept(department.getDeptName());
                                                } else {
                                                    closedB.setDept("未指定部门");

                                                }

                                                closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend3.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);

                                            }
                                        }
                                    } else {
                                        status = "weiqiandao";
                                        BaseSupplement notOutthree = new BaseSupplement();
                                        notOutthree.setUid(uid);
                                        notOutthree.setName(users.getName());
                                        notOutthree.setAvatar(users.getAvatar());
                                        if (users.getDeptId() != null && users.getDeptId() != 0) {
                                            Department department = departmentMapper.getDeptById(users.getDeptId());
                                            if (department != null) {
                                                notOutthree.setDept(department.getDeptName());
                                            } else {
                                                notOutthree.setDept("未指定部门");
                                            }

                                        } else {
                                            notOutthree.setDept("未指定部门");
                                        }

                                        notOutthree.setStr("未签退(规定签到时间为：" + attendSet.getAtime3() + ")");
                                        notOutNumber.setStr("签到时间为：" + attendSet.getAtime3());
                                        notOut.add(notOutthree);
                                    }
                                }
                            }
                        }
                        if (numberOne.equals(attendSet.getAtime4Setother())) {
                            if (DateFormat.getDateTimes(attendSet.getAtime4()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {
                                String status = "";
                                if (numberOne.equals(attendSet.getCommute4())) {
                                    Attend attend4 = attendMapper.selectAttendAll(date, uid, numberFour);
                                    if (attend4 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend4.getAtime());
                                        if (this.reTime(attend4.getAtime()) > DateFormat.getDateTimes(attendSet.getAtime4()).getTime()) {
                                            status = "迟到";
                                            BaseSupplement latefour = new BaseSupplement();
                                            latefour.setUid(uid);
                                            latefour.setName(users.getName());
                                            latefour.setAvatar(users.getAvatar());
                                            if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                Department department = departmentMapper.getDeptById(users.getDeptId());

                                                latefour.setDept(department.getDeptName());
                                            } else {
                                                latefour.setDept("未指定部门");
                                            }

                                            latefour.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend4.getAtime()) + "迟到(" + DateFormat.returnTime(this.reTime(attend4.getAtime()).intValue() - DateFormat.getWYQTime(attendSet.getAtime4())) + ")");
                                            lateNumber.setStr("签到时间为：" + attendSet.getAtime4());

                                            late.add(latefour);
                                        } else {
                                            status = "正常";
                                            String msg = companyAttendanceException(date, uid, numberFour);
                                            if (!StringUtils.checkNull(msg)) {
                                                normalyichangB.setUid(uid);
                                                normalyichangB.setName(users.getName());
                                                normalyichangB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    normalyichangB.setDept(department.getDeptName());
                                                } else {
                                                    normalyichangB.setDept("未指定部门");

                                                }
                                                normalyichangB.setStr(msg);

                                            } else {
                                                normalB.setUid(uid);
                                                normalB.setName(users.getName());
                                                normalB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    normalB.setDept(department.getDeptName());
                                                } else {
                                                    normalB.setDept("未指定部门");

                                                }

                                                normalB.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend4.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);

                                            }
                                        }

                                    } else {
                                        status = "weiqiandao";
                                        BaseSupplement notSignfour = new BaseSupplement();
                                        notSignfour.setUid(uid);
                                        notSignfour.setName(users.getName());
                                        notSignfour.setAvatar(users.getAvatar());
                                        if (users.getDeptId() != null && users.getDeptId() != 0) {
                                            Department department = departmentMapper.getDeptById(users.getDeptId());

                                            notSignfour.setDept(department.getDeptName());
                                        } else {
                                            notSignfour.setDept("未指定部门");
                                        }
                                        notSignfour.setStr("未签到(规定签到时间为：" + attendSet.getAtime4() + ")");
                                        notSignNumber.setStr("签到时间为：" + attendSet.getAtime4());
                                        notSign.add(notSignfour);
                                    }
                                } else {
                                    Attend attend4 = attendMapper.selectAttendAll(date, uid, numberFour);
                                    if (attend4 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend4.getAtime());
                                        if (this.reTime(attend4.getAtime()) < DateFormat.getDateTimes(attendSet.getAtime4()).getTime()) {
                                            status = "早退";
                                            BaseSupplement leaveEarlyfour = new BaseSupplement();
                                            leaveEarlyfour.setUid(uid);
                                            leaveEarlyfour.setName(users.getName());
                                            leaveEarlyfour.setAvatar(users.getAvatar());
                                            if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                Department department = departmentMapper.getDeptById(users.getDeptId());

                                                leaveEarlyfour.setDept(department.getDeptName());
                                            } else {
                                                leaveEarlyfour.setDept("未指定部门");
                                            }
                                            leaveEarlyfour.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend4.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime4()) - attend4.getAtime()) + ")");
                                            leaveEarlyNumber.setStr("签到时间为：" + attendSet.getAtime4());
                                            leaveEarly.add(leaveEarlyfour);
                                        } else {
                                            status = "正常";
                                            String msg = companyAttendanceException(date, uid, numberFour);
                                            if (!StringUtils.checkNull(msg)) {
                                                closedyichangB.setUid(uid);
                                                closedyichangB.setName(users.getName());
                                                closedyichangB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    closedyichangB.setDept(department.getDeptName());
                                                } else {
                                                    closedyichangB.setDept("未指定部门");

                                                }
                                                closedyichangB.setStr(msg);

                                            } else {
                                                closedB.setUid(uid);
                                                closedB.setName(users.getName());
                                                closedB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    closedB.setDept(department.getDeptName());
                                                } else {
                                                    closedB.setDept("未指定部门");

                                                }

                                                closedB.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend4.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);

                                            }
                                        }

                                    } else {
                                        status = "weiqiandao";
                                        BaseSupplement notOutfour = new BaseSupplement();
                                        notOutfour.setUid(uid);
                                        notOutfour.setName(users.getName());
                                        notOutfour.setAvatar(users.getAvatar());
                                        if (users.getDeptId() != null && users.getDeptId() != 0) {
                                            Department department = departmentMapper.getDeptById(users.getDeptId());

                                            notOutfour.setDept(department.getDeptName());
                                        } else {
                                            notOutfour.setDept("未指定部门");
                                        }
                                        notOutfour.setStr("未签退(规定签到时间为：" + attendSet.getAtime4() + ")");
                                        notOutNumber.setStr("签到时间为：" + attendSet.getAtime4());
                                        notOut.add(notOutfour);
                                    }


                                }

                            }
                        }
                        if (numberOne.equals(attendSet.getAtime5Setother())) {

                            if (DateFormat.getDateTimes(attendSet.getAtime5()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                                String status = "";
                                if (numberOne.equals(attendSet.getCommute5())) {
                                    Attend attend5 = attendMapper.selectAttendAll(date, uid, numberFive);
                                    if (attend5 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend5.getAtime());
                                        if (this.reTime(attend5.getAtime()) > DateFormat.getDateTimes(attendSet.getAtime5()).getTime()) {
                                            status = "迟到";
                                            BaseSupplement latefive = new BaseSupplement();
                                            latefive.setUid(uid);
                                            latefive.setName(users.getName());
                                            latefive.setAvatar(users.getAvatar());
                                            if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                Department department = departmentMapper.getDeptById(users.getDeptId());

                                                latefive.setDept(department.getDeptName());
                                            } else {
                                                latefive.setDept("未指定部门");
                                            }
                                            latefive.setStr("签到时间为：" + attendSet.getAtime5() + "迟到(" + DateFormat.parseMillisecone(this.reTime(attend5.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime5())) + ")");
                                            lateNumber.setStr("签到时间为：" + attendSet.getAtime5());

                                            late.add(latefive);
                                        } else {
                                            status = "正常";
                                            String msg = companyAttendanceException(date, uid, numberFive);
                                            if (!StringUtils.checkNull(msg)) {
                                                normalyichangB.setUid(uid);
                                                normalyichangB.setName(users.getName());
                                                normalyichangB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    normalyichangB.setDept(department.getDeptName());
                                                } else {
                                                    normalyichangB.setDept("未指定部门");

                                                }
                                                normalyichangB.setStr(msg);

                                            } else {
                                                normalB.setUid(uid);
                                                normalB.setName(users.getName());
                                                normalB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    normalB.setDept(department.getDeptName());
                                                } else {
                                                    normalB.setDept("未指定部门");

                                                }

                                                normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend5.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);

                                            }
                                        }

                                    } else {
                                        status = "weiqiandao";
                                        BaseSupplement notSignfive = new BaseSupplement();
                                        notSignfive.setUid(uid);
                                        notSignfive.setName(users.getName());
                                        notSignfive.setAvatar(users.getAvatar());
                                        if (users.getDeptId() != null && users.getDeptId() != 0) {
                                            Department department = departmentMapper.getDeptById(users.getDeptId());

                                            notSignfive.setDept(department.getDeptName());
                                        } else {
                                            notSignfive.setDept("未指定部门");
                                        }
                                        notSignfive.setStr("未签到(规定签到时间为：" + attendSet.getAtime5() + ")");
                                        notSignNumber.setStr("签到时间为：" + attendSet.getAtime5());
                                        notSign.add(notSignfive);
                                    }
                                } else {
                                    Attend attend5 = attendMapper.selectAttendAll(date, uid, numberFive);
                                    if (attend5 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend5.getAtime());
                                        if (this.reTime(attend5.getAtime()) < DateFormat.getDateTimes(attendSet.getAtime5()).getTime()) {
                                            status = "早退";
                                            BaseSupplement leaveEarlyfive = new BaseSupplement();
                                            leaveEarlyfive.setUid(uid);
                                            leaveEarlyfive.setName(users.getName());
                                            leaveEarlyfive.setAvatar(users.getAvatar());
                                            if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                Department department = departmentMapper.getDeptById(users.getDeptId());

                                                leaveEarlyfive.setDept(department.getDeptName());
                                            } else {
                                                leaveEarlyfive.setDept("未指定部门");
                                            }
                                            leaveEarlyfive.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend5.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime5()) - attend5.getAtime()) + ")");
                                            leaveEarlyNumber.setStr("签到时间为：" + attendSet.getAtime5());
                                            leaveEarly.add(leaveEarlyfive);
                                        } else {
                                            status = "正常";
                                            String msg = companyAttendanceException(date, uid, numberFive);
                                            if (!StringUtils.checkNull(msg)) {
                                                closedyichangB.setUid(uid);
                                                closedyichangB.setName(users.getName());
                                                closedyichangB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    closedyichangB.setDept(department.getDeptName());
                                                } else {
                                                    closedyichangB.setDept("未指定部门");

                                                }
                                                closedyichangB.setStr(msg);

                                            } else {
                                                closedB.setUid(uid);
                                                closedB.setName(users.getName());
                                                closedB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    closedB.setDept(department.getDeptName());
                                                } else {
                                                    closedB.setDept("未指定部门");

                                                }

                                                closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend5.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);

                                            }

                                        }

                                    } else {
                                        status = "weiqiandao";
                                        BaseSupplement notOutfive = new BaseSupplement();
                                        notOutfive.setUid(uid);
                                        notOutfive.setName(users.getName());
                                        notOutfive.setAvatar(users.getAvatar());
                                        if (users.getDeptId() != null && users.getDeptId() != 0) {
                                            Department department = departmentMapper.getDeptById(users.getDeptId());

                                            notOutfive.setDept(department.getDeptName());
                                        } else {
                                            notOutfive.setDept("未指定部门");
                                        }
                                        notOutfive.setStr("未签退(规定签到时间为：" + attendSet.getAtime1() + ")");
                                        notOutNumber.setStr("签到时间为：" + attendSet.getAtime5());
                                        notOut.add(notOutfive);
                                    }


                                }
                            }

                        }
                        if (numberOne.equals(attendSet.getAtime6Setother())) {
                            if (DateFormat.getDateTimes(attendSet.getAtime6()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {
                                String status = "";
                                if (numberOne.equals(attendSet.getCommute6())) {
                                    Attend attend6 = attendMapper.selectAttendAll(date, uid, numberSix);
                                    if (attend6 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend6.getAtime());
                                        if (this.reTime(attend6.getAtime()) > DateFormat.getDateTimes(attendSet.getAtime6()).getTime()) {
                                            status = "迟到";
                                            BaseSupplement latesix = new BaseSupplement();
                                            latesix.setUid(uid);
                                            latesix.setName(users.getName());
                                            latesix.setAvatar(users.getAvatar());
                                            if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                Department department = departmentMapper.getDeptById(users.getDeptId());

                                                latesix.setDept(department.getDeptName());
                                            } else {
                                                latesix.setDept("未指定部门");
                                            }
                                            latesix.setStr("签到时间为：" + attendSet.getAtime6() + "迟到(" + DateFormat.parseMillisecone(this.reTime(attend6.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime6())) + ")");
                                            lateNumber.setStr("签到时间为：" + attendSet.getAtime6());

                                            late.add(latesix);
                                        } else {
                                            status = "正常";
                                            String msg = companyAttendanceException(date, uid, numberSix);
                                            if (!StringUtils.checkNull(msg)) {
                                                normalyichangB.setUid(uid);
                                                normalyichangB.setName(users.getName());
                                                normalyichangB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    normalyichangB.setDept(department.getDeptName());
                                                } else {
                                                    normalyichangB.setDept("未指定部门");

                                                }
                                                normalyichangB.setStr(msg);

                                            } else {
                                                normalB.setUid(uid);
                                                normalB.setName(users.getName());
                                                normalB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    normalB.setDept(department.getDeptName());
                                                } else {
                                                    normalB.setDept("未指定部门");

                                                }

                                                normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend6.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);

                                            }
                                        }
                                    } else {
                                        status = "weiqiandao";
                                        BaseSupplement notSignsix = new BaseSupplement();
                                        notSignsix.setUid(uid);
                                        notSignsix.setName(users.getName());
                                        notSignsix.setAvatar(users.getAvatar());
                                        if (users.getDeptId() != null && users.getDeptId() != 0) {
                                            Department department = departmentMapper.getDeptById(users.getDeptId());

                                            notSignsix.setDept(department.getDeptName());
                                        } else {
                                            notSignsix.setDept("未指定部门");
                                        }
                                        notSignsix.setStr("未签到(规定签到时间为：" + attendSet.getAtime6() + ")");
                                        notSignNumber.setStr("签到时间为：" + attendSet.getAtime6());

                                        notSign.add(notSignsix);
                                    }
                                } else {
                                    Attend attend6 = attendMapper.selectAttendAll(date, uid, numberSix);
                                    if (attend6 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend6.getAtime());
                                        if (this.reTime(attend6.getAtime()) < DateFormat.getDateTimes(attendSet.getAtime6()).getTime()) {
                                            status = "早退";
                                            BaseSupplement leaveEarlysix = new BaseSupplement();
                                            leaveEarlysix.setUid(uid);
                                            leaveEarlysix.setName(users.getName());
                                            leaveEarlysix.setAvatar(users.getAvatar());
                                            if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                Department department = departmentMapper.getDeptById(users.getDeptId());

                                                leaveEarlysix.setDept(department.getDeptName());
                                            } else {
                                                leaveEarlysix.setDept("未指定部门");
                                            }
                                            leaveEarlysix.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend6.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime6()) - attend6.getAtime()) + ")");
                                            leaveEarlyNumber.setStr("签到时间为：" + attendSet.getAtime6());

                                            leaveEarly.add(leaveEarlysix);
                                        } else {
                                            status = "正常";
                                            String msg = companyAttendanceException(date, uid, numberSix);
                                            if (!StringUtils.checkNull(msg)) {
                                                closedyichangB.setUid(uid);
                                                closedyichangB.setName(users.getName());
                                                closedyichangB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    closedyichangB.setDept(department.getDeptName());
                                                } else {
                                                    closedyichangB.setDept("未指定部门");

                                                }
                                                closedyichangB.setStr(msg);

                                            } else {
                                                closedB.setUid(uid);
                                                closedB.setName(users.getName());
                                                closedB.setAvatar(users.getAvatar());
                                                if (users.getDeptId() != null && users.getDeptId() != 0) {
                                                    Department department = departmentMapper.getDeptById(users.getDeptId());
                                                    closedB.setDept(department.getDeptName());
                                                } else {
                                                    closedB.setDept("未指定部门");

                                                }

                                                closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend6.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);

                                            }
                                        }

                                    } else {
                                        status = "weiqiandao";
                                        BaseSupplement notOutsix = new BaseSupplement();
                                        notOutsix.setUid(uid);
                                        notOutsix.setName(users.getName());
                                        notOutsix.setAvatar(users.getAvatar());
                                        if (users.getDeptId() != null && users.getDeptId() != 0) {
                                            Department department = departmentMapper.getDeptById(users.getDeptId());

                                            notOutsix.setDept(department.getDeptName());
                                        } else {
                                            notOutsix.setDept("未指定部门");
                                        }
                                        notOutsix.setStr("未签退(规定签到时间为：" + attendSet.getAtime6() + ")");
                                        notOutNumber.setStr("签到时间为：" + attendSet.getAtime6());

                                        notOut.add(notOutsix);
                                    }


                                }
                            }
                        }


                    }
                    if (!StringUtils.checkNull(lateNumber.getStr())) {
                        lateNumbers.add(lateNumber);
                    }
                    if (!StringUtils.checkNull(notOutNumber.getStr())) {
                        notOutNumbers.add(notOutNumber);
                    }
                    if (!StringUtils.checkNull(leaveEarlyNumber.getStr())) {
                        leaveEarlyNumbers.add(leaveEarlyNumber);
                    }
                    if (!StringUtils.checkNull(notSignNumber.getStr())) {
                        notSignNumbers.add(notSignNumber);
                    }
                    if (normalB.getUid() != null) {
                        normal.add(normalB);
                    }

                    if (normalyichangB.getUid() != null) {
                        normalyichang.add(normalyichangB);
                    }
                    if (closedB.getUid() != null) {
                        closed.add(closedB);
                    }
                    if (closedyichangB.getUid() != null) {
                        closedyichang.add(closedyichangB);
                    }


                }
            }


            Attend normalAttend = new Attend();
            normalAttend.setSname("上班正常");
            if (normal.size() > 0) {
                normalAttend.setNum(normal.size() + "人");
                normalAttend.setState(numberOne);
            } else {
                normalAttend.setNum(numberZero);
                normalAttend.setState(numberZero);
            }
            normalAttend.setType("天");
            normalAttend.setBaseSupplements(normal);
            Attend normalyichangAttend = new Attend();
            normalyichangAttend.setSname("上班异常");
            if (normalyichang.size() > 0) {
                normalyichangAttend.setNum(normalyichang.size() + "人");
                normalyichangAttend.setState(numberOne);
            } else {
                normalyichangAttend.setNum(numberZero);
                normalyichangAttend.setState(numberZero);
            }
            normalyichangAttend.setType("天");
            normalyichangAttend.setBaseSupplements(normalyichang);
            Attend closedAttend = new Attend();
            closedAttend.setSname("下班正常");
            if (closed.size() > 0) {
                closedAttend.setNum(closed.size() + "人");
                closedAttend.setState(numberOne);
            } else {
                closedAttend.setNum(numberZero);
                closedAttend.setState(numberZero);
            }
            closedAttend.setType("天");
            closedAttend.setBaseSupplements(closed);

            Attend closedyichangAttend = new Attend();
            closedyichangAttend.setSname("下班异常");
            if (closedyichang.size() > 0) {
                closedyichangAttend.setNum(closedyichang.size() + "人");
                closedyichangAttend.setState(numberOne);
            } else {
                closedyichangAttend.setNum(numberZero);
                closedyichangAttend.setState(numberZero);
            }
            closedyichangAttend.setType("天");
            closedyichangAttend.setBaseSupplements(closedyichang);
            Attend notSignAttend = new Attend();
            notSignAttend.setSname("未签到");
            if (notSign.size() > 0) {
                notSignAttend.setNum(notSignNumbers.size() + "人");
                notSignAttend.setState(numberOne);
            } else {
                notSignAttend.setNum(numberZero);
                notSignAttend.setState(numberZero);
            }
            notSignAttend.setType("次");
            notSignAttend.setBaseSupplements(notSign);
            Attend notOutAttend = new Attend();
            notOutAttend.setSname("未签退");
            if (notOut.size() > 0) {
                notOutAttend.setNum(notOutNumbers.size() + "人");
                notOutAttend.setState(numberOne);
            } else {
                notOutAttend.setNum(numberZero);
                notOutAttend.setState(numberZero);
            }
            notOutAttend.setType("次");
            notOutAttend.setBaseSupplements(notOut);
            Attend lateAttend = new Attend();
            lateAttend.setSname("迟到");
            if (late.size() > 0) {
                lateAttend.setNum(lateNumbers.size() + "人");
                lateAttend.setState(numberOne);
            } else {
                lateAttend.setNum(numberZero);
                lateAttend.setState(numberZero);
            }
            lateAttend.setType("次");
            lateAttend.setBaseSupplements(late);

            Attend leaveEarlyAttend = new Attend();
            leaveEarlyAttend.setSname("早退");
            if (leaveEarly.size() > 0) {
                leaveEarlyAttend.setNum(leaveEarlyNumbers.size() + "人");
                leaveEarlyAttend.setState(numberOne);
            } else {
                leaveEarlyAttend.setNum(numberZero);
                leaveEarlyAttend.setState(numberZero);
            }
            leaveEarlyAttend.setType("次");
            leaveEarlyAttend.setBaseSupplements(leaveEarly);

            Attend fileAttend = new Attend();
            fileAttend.setSname("外勤");
            if (filds.size() > 0) {
                fileAttend.setNum(filds.size() + "人");
                fileAttend.setState(numberOne);
            } else {
                fileAttend.setNum(numberZero);
                fileAttend.setState(numberZero);
            }
            fileAttend.setType("次");
            fileAttend.setBaseSupplements(filds);

            Attend qingjiaAttend = new Attend();
            qingjiaAttend.setSname("请假");
            if (leaves.size() > 0) {
                qingjiaAttend.setNum(leaves.size() + "人");
                qingjiaAttend.setState(numberOne);
            } else {
                qingjiaAttend.setNum(numberZero);
                qingjiaAttend.setState(numberZero);
            }
            qingjiaAttend.setType("次");
            qingjiaAttend.setBaseSupplements(leaves);

            Attend waichuAttend = new Attend();
            waichuAttend.setSname("外出");
            if (waichu.size() > 0) {
                waichuAttend.setNum(waichu.size() + "人");
                waichuAttend.setState(numberOne);
            } else {
                waichuAttend.setNum(numberZero);
                waichuAttend.setState(numberZero);
            }
            waichuAttend.setType("次");
            waichuAttend.setBaseSupplements(waichu);

            Attend chuchaAttend = new Attend();
            chuchaAttend.setSname("出差");
            if (chucha.size() > 0) {
                chuchaAttend.setNum(chucha.size() + "人");
                chuchaAttend.setState(numberOne);
            } else {
                chuchaAttend.setNum(numberZero);
                chuchaAttend.setState(numberZero);
            }
            chuchaAttend.setType("次");
            chuchaAttend.setBaseSupplements(chucha);


            Attend attend = new Attend();
            attend.setUserAll(usersList.size());
            attend.setUserSize(chuqinRenshu);

            List<Attend> attendList = new ArrayList<Attend>();
            attendList.add(normalyichangAttend);
            attendList.add(normalAttend);
            attendList.add(closedyichangAttend);
            attendList.add(closedAttend);
            attendList.add(notSignAttend);
            attendList.add(notOutAttend);
            attendList.add(lateAttend);
            attendList.add(leaveEarlyAttend);
            attendList.add(fileAttend);
            attendList.add(chuchaAttend);
            attendList.add(qingjiaAttend);
            attendList.add(waichuAttend);
            attend.setList(attendList);
            wrappers.setFlag(true);
            wrappers.setStatus(true);
            wrappers.setData(attend);
            wrappers.setMsg("更新成功");
        } catch (Exception e) {
            e.printStackTrace();
            wrappers.setFlag(false);
            wrappers.setStatus(true);
            wrappers.setMsg("更新失败");
        }

        //公司考勤收尾
        return wrappers;
    }

    //    手机端-按日期查看明细（我的签到）
    public BaseWrapper normalCondition(String year, String month, HttpServletRequest request) throws ParseException {
        AttendSetWrappers wrappers = new AttendSetWrappers();
        Attend attend = new Attend();

        String date = year + "-" + month;
        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionId);
        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM");
        String time1 = format1.format(new Date());
        Date s = format1.parse(date);

        if (s.getTime() <= new Date().getTime()) {

            List<BaseAttend> baseAttends = new ArrayList<BaseAttend>();
            List<Date> datss = new ArrayList<Date>();
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
            SimpleDateFormat matter2 = new SimpleDateFormat("yyyy-MM-dd");
            Date dt = new Date();
            String a11 = df.format(dt);//获取当前日期
            String stratDate = "";
            String endDate = "";
            if (date.equals(a11)) {
                stratDate = date + "-01";
                endDate = matter2.format(dt);//获取当前日期时间

            } else {
                Date date1 = df.parse(date);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date1);
                int last1 = calendar.getActualMaximum(calendar.DAY_OF_MONTH);    //获取本月最大天数
                stratDate = date + "-01";
                endDate = date + "-" + last1;
            }
            Date start1 = matter2.parse(stratDate);
            Date end1 = matter2.parse(endDate);
            Calendar c = Calendar.getInstance();
            List<Date> dates = DateCompute.getBetweenDates(start1, end1);

            //确定一个月需要上班的日期
            for (Date nowdate1 : dates) {
                c.setTime(nowdate1);
                int weekInt = c.get(Calendar.DAY_OF_WEEK);
                weekInt = weekInt - 1;
                if (weekInt == 0) {
                    weekInt = 7;
                }
                AttendSet attendSet = null;
                UserDuty userDuty = userDutyMapper.userDuty(users.getUid(), matter2.format(nowdate1));
                if (userDuty != null) {
                    attendSet = attendSetMapper.selectAttendSetSid(userDuty.getDutyType());
                    String week = String.valueOf(weekInt);
                    if (attendSet.getWorkdate().contains(week)) {
                        datss.add(nowdate1);
                    }
                }
            }
///////////-----去除节假日------------年假-------请假     ///////////////加上----------------调休-------------加班-------值班-----（后期加上）

            AttendSet attendSet = null;
            for (Date nowdate : datss) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("uid", users.getUid());
                map.put("date", DateFormat.getDatestr(nowdate));
                List<Attend> attendListzhengchang = attendMapper.selectAttendList(map);

                BaseAttend baseAttend = new BaseAttend();
                baseAttend.setAtime(DateFormat.getDatestr(nowdate));

                String ndate = matter2.format(nowdate);

                UserDuty userDuty = userDutyMapper.userDuty(users.getUid(), ndate);
                if (userDuty != null) {
                    attendSet = attendSetMapper.selectAttendSetSid(userDuty.getDutyType());

                    int xqhbt = 0;
                    String[] str1 = attendSet.getAtime1Set().split("\\|");
                    if (numberOne.equals(str1[0])) {
                        xqhbt++;
                    }
                    attendSet.setAtime1Setother(str1[0]);
                    attendSet.setCommute1(str1[1]);
                    String[] str2 = attendSet.getAtime2Set().split("\\|");
                    if (numberOne.equals(str2[0])) {
                        xqhbt++;
                    }
                    attendSet.setAtime2Setother(str2[0]);
                    attendSet.setCommute2(str2[1]);
                    String[] str3 = attendSet.getAtime3Set().split("\\|");
                    if (numberOne.equals(str3[0])) {
                        xqhbt++;
                    }
                    attendSet.setAtime3Setother(str3[0]);
                    attendSet.setCommute3(str3[1]);
                    String[] str4 = attendSet.getAtime4Set().split("\\|");
                    if (numberOne.equals(str4[0])) {
                        xqhbt++;
                    }
                    attendSet.setAtime4Setother(str4[0]);
                    attendSet.setCommute4(str4[1]);
                    String[] str5 = attendSet.getAtime5Set().split("\\|");
                    if (numberOne.equals(str5[0])) {
                        xqhbt++;
                    }
                    attendSet.setAtime5Setother(str5[0]);
                    attendSet.setCommute5(str5[1]);
                    String[] str6 = attendSet.getAtime6Set().split("\\|");
                    if (numberOne.equals(str6[0])) {
                        xqhbt++;
                    }
                    attendSet.setAtime6Setother(str6[0]);
                    attendSet.setCommute6(str6[1]);


                    if (attendListzhengchang != null && attendListzhengchang.size() == xqhbt) {
                        baseAttend.setStr(numberOne);
                    } else {
                        baseAttend.setStr(numberZero);
                    }
                    baseAttends.add(baseAttend);

                }
            }
            Attend attendzhengchang = new Attend();
            attendzhengchang.setRemarksList(baseAttends);
            wrappers.setFlag(true);
            wrappers.setStatus(true);
            wrappers.setData(attendzhengchang);
            wrappers.setMsg("更新成功");
            return wrappers;
        } else {
            wrappers.setFlag(false);
            wrappers.setStatus(true);
            wrappers.setMsg("更新失败");
            return wrappers;
        }


    }

    public static String attendDatetime = "08:00:00";

    public static List<Date> findDates(Date dBegin, Date dEnd) {
        List<Date> lDate = new ArrayList<Date>();
        lDate.add(dBegin);
        Calendar calBegin = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calBegin.setTime(dBegin);
        Calendar calEnd = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calEnd.setTime(dEnd);
        // 测试此日期是否在指定日期之后
        while (dEnd.after(calBegin.getTime())) {
            // 根据日历的规则，为给定的日历字段添加或减去指定的时间量
            calBegin.add(Calendar.DAY_OF_MONTH, 1);
            lDate.add(calBegin.getTime());
        }
        return lDate;
    }

    /**
     * @author 程叶同
     * @date 2018/7/30 12:48
     * @desc 日期时段获取
     */
    public List<Date> getDateAmones(String begDateStr, String endDateStr) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date begDate = sdf.parse(begDateStr);
        Date endDate = sdf.parse(endDateStr);
        if (begDate.after(endDate)) {
            throw new RuntimeException("日期范围非法");
        }
        // 总天数
        int days = (int) ((endDate.getTime() - begDate.getTime()) / (24 * 60 * 60 * 1000)) + 1;
        // 总周数，
        int weeks = days / 7;
        int rs = 0;
        // 整数周
        if (days % 7 == 0) {
            rs = days - 2 * weeks;
        } else {
            Calendar begCalendar = Calendar.getInstance();
            Calendar endCalendar = Calendar.getInstance();
            begCalendar.setTime(begDate);
            endCalendar.setTime(endDate);
            // 周日为1，周六为7
            int beg = begCalendar.get(Calendar.DAY_OF_WEEK);
            int end = endCalendar.get(Calendar.DAY_OF_WEEK);
            if (beg > end) {
                rs = days - 2 * (weeks + 1);
            } else if (beg < end) {
                if (end == 7) {
                    rs = days - 2 * weeks - 1;
                } else {
                    rs = days - 2 * weeks;
                }
            } else {
                if (beg == 1 || beg == 7) {
                    rs = days - 2 * weeks - 1;
                } else {
                    rs = days - 2 * weeks;
                }
            }
        }
        List<Date> dates = new ArrayList<>();
        if (rs <= 1) {
            dates.add(begDate);
        } else if (rs > 1) {
            List<Date> dates1 = findDates(begDate, endDate);
            dates.addAll(dates1);
        }
        return dates;
    }

    public BaseWrapper personalAttend(String attendDate, HttpServletRequest req) throws ParseException {
        AttendSetWrappers wrappers = new AttendSetWrappers();
        Cookie redisSessionId = CookiesUtil.getCookieByName(req, "redisSessionId");
        String sqlType = "xoa"+SessionUtils.getSessionInfo(req.getSession(), "loginDateSouse", String.class, redisSessionId);
        Integer uid = SessionUtils.getSessionInfo(req.getSession(), Users.class, new Users(), redisSessionId).getUid();
        try {
            List<Attend> resultList = new ArrayList<>();
            List<AttendSet> attendSetList = new ArrayList<>();
            //暂存考勤类型（避免重复查询数据库）
            Map<Integer, AttendSet> attendSetMap = new HashMap<>();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
            List<String> monthMaxDay = new ArrayList<>();
            if (simpleDateFormat.format(new Date()).equals(attendDate)) {
                monthMaxDay = AttendDateUtil.getMonthMaxDay();
            } else {
                monthMaxDay = AttendDateUtil.getMonthMaxDay(attendDate);
            }
            String startDate = monthMaxDay.get(0);
            String endDate = monthMaxDay.get(monthMaxDay.size() - 1);
            //查找当前用户的排班
            List<UserDuty> userDutyList = userDutyMapper.getUserDutyListByUidAndDates(uid, startDate, endDate);
            if (userDutyList != null && userDutyList.size() > 0) {
                //根据uid和日期查找用户的固定签到信息
                List<Attend> attendList = attendMapper.getAttendListByUidAndDates(uid, startDate, endDate);
                //根据uid和日期查找用户的自由签到信息
                List<Attend> attendByUidDatesType = attendMapper.getAttendByUidDatesType(uid, startDate, endDate);
                //固定签到信息按日期分组
                Map<String, Map<String, Attend>> groudAttendMap = groudAttendByDateType(attendList);
                //自由签到信息按日期分组
                Map<String, List<Attend>> stringListMap = groudAttendByDate(attendByUidDatesType);
                for (UserDuty userDuty : userDutyList) {
                    //存储每天多次的签到信息
                    List<Attend> workList = new ArrayList<>();
                    String AttendSetType = "0";
                    //（-1-下班早退，0-正常，1-上班迟到）默认正常
                    String attendStatus = numberZero;
                    //展示信息
                    String status = "";
                    //实际签到时间(时间戳/秒)
                    int atime = 0;
                    //实际签到时间("HH:mm:ss"),未签到的话 就是 应签到时间
                    String time = "";
                    //备注
                    String remark = "";
                    //签到地点
                    String addres = "";
                    //仅设置调休上班
                    if (userDuty.getAddType().equals("2")) {
                        status = "调休上班";
                    }
                    //节假日
                    if (userDuty.getAddType().contains("3")) {
                        Attend attendRetur = new Attend();
                        AttendSetType = "3";
                        status = "节假日";
                        remark = "节假日无需签到";
                        attendRetur.setDateName(userDuty.getDutyDate());
                        attendRetur.setAttendSetType(AttendSetType);
                        attendRetur.setAtimestate(status);
                        attendRetur.setAddress(addres);
                        attendRetur.setAtime(atime);
                        attendRetur.setTime(time);
                        attendRetur.setRemark(remark);
                        workList.add(attendRetur);
                    } else {
                        //获取考勤类型
                        Integer userDutyType = userDuty.getDutyType();
                        if (userDutyType == null){
                            continue;
                        }
                        AttendSet attendSet = attendSetMap.get(userDutyType);
                        if (attendSet == null) {
                            attendSet = attendSetMapper.selectAttendSetSid(userDutyType);
                            attendSetMap.put(userDutyType, attendSet);
                            attendSetList.add(attendSet);
                        }
                        //获取用户当天所有的签到信息
                        Map<String, Attend> attendMap = groudAttendMap.get(userDuty.getDutyDate());
                        if (attendSet != null) {
                            //固定签到
                            AttendSetType = attendSet.getAttendType();
                            if ("0".equals(attendSet.getAttendType())) {
                                Class c = attendSet.getClass().forName("com.xoa.model.attend.AttendSet");
                                c.newInstance();
                                for (int i = 1; i <= 6; i++) {
                                    Method methodget = c.getMethod("getAtime" + i + "Set");
                                    String getAtimeSet = (String) methodget.invoke(attendSet);
                                    if (getAtimeSet != null && getAtimeSet.contains("|")) {
                                        String[] getAtimeSets = getAtimeSet.split("\\|");
                                        String kaiguan = getAtimeSets[0];
                                        String type = getAtimeSets[1];
                                        //如果启动
                                        if (kaiguan.equals("1")) {
                                            Method methodGetAtime = c.getMethod("getAtime" + i);
                                            String getAtime = (String) methodGetAtime.invoke(attendSet);
                                            if (!StringUtils.checkNull(getAtime) && getAtime.length() < 10) {
                                                time = getAtime;
                                                getAtime = userDuty.getDutyDate() + " " + getAtime;
                                            }else{
                                                time = "00:00:00";
                                                getAtime = userDuty.getDutyDate() + " 00:00:00";
                                            }


                                            //应签到时间 时间戳（秒）
                                            Integer yAtime = DateFormat.getNowDateTime(getAtime);
                                            //查看的签到信息
                                            if (attendMap != null) {
                                                Attend dutyAttend = attendMap.get(String.valueOf(i));
                                                //如果有签到，查看是否正常
                                                if (dutyAttend != null) {
                                                    //注意，此为秒级时间戳.签到时间
                                                    atime = dutyAttend.getAtime();
                                                    if (type.equals("1")) {
                                                        if (atime > yAtime) {
                                                            status = "上班迟到";
                                                            attendStatus = numberOne;
                                                        } else {
                                                            status = "上班正常";
                                                            attendStatus = numberZero;
                                                        }
                                                    } else if (type.equals("2")) {
                                                        if (atime < yAtime) {
                                                            status = "下班早退";
                                                            attendStatus = "-1";
                                                        } else {
                                                            status = "下班正常";
                                                            attendStatus = numberZero;
                                                        }
                                                    }
                                                    remark = dutyAttend.getRemark();
                                                    addres = dutyAttend.getAddress();
                                                    time = DateFormat.getwyqStrTime(atime);
                                                } else {
                                                    status = "未签到";
                                                }
                                            } else {
                                                status = "未签到";
                                            }
                                            Attend attendRetur = new Attend();
                                            attendRetur.setNum(numberOne);
                                            attendRetur.setSwi(numberOne);
                                            attendRetur.setDateName(userDuty.getDutyDate());
                                            attendRetur.setAttendSetType(AttendSetType);
                                            attendRetur.setAttendStatus(attendStatus);
                                            attendRetur.setAtimestate(status);
                                            attendRetur.setAddress(addres);
                                            attendRetur.setAtime(atime);
                                            attendRetur.setTime(time);
                                            attendRetur.setRemark(remark);
                                            workList.add(attendRetur);
                                        }
                                    }
                                }
                                //弹性工时
                            } else if ("1".equals(attendSet.getAttendType())) {
                                List<Attend> list = stringListMap.get(userDuty.getDutyDate());
                                if (list != null && list.size() > 0) {
                                    int i = 0;
                                    Integer startTime = 0;
                                    do {
                                        Attend dutyAttend = list.get(i);
                                        dutyAttend.setNum(list.size() + "");
                                        dutyAttend.setSwi(list.size() + "");
                                        dutyAttend.setDateName(userDuty.getDutyDate());
                                        dutyAttend.setAttendSetType(AttendSetType);
                                        dutyAttend.setAttendStatus(attendStatus);
                                        dutyAttend.setWorkHours(attendSet.getWorkHours() + "小时");
                                        //计算工作时长
                                        if (startTime != 0) {
                                            Integer timea = dutyAttend.getAtime() - startTime;
                                            String workHours = DateFormat.returnTime(timea);
                                            dutyAttend.setIsFullAttend(timea >= Integer.valueOf(attendSet.getWorkHours()) * 60 * 60);
                                            dutyAttend.setActualWorkHours(workHours);
                                        }
                                        startTime = dutyAttend.getAtime();
                                        status = i == 0 ? "第一次签到" : "最后一次签到";
                                        String sstr = "1";
                                        sstr = i == 0 ? "1" : "2";
                                        dutyAttend.setCommute(sstr);
                                        time = DateFormat.getwyqStrTime(startTime);
                                        dutyAttend.setAtimestate(status);
                                        dutyAttend.setTime(time);
                                        workList.add(dutyAttend);
                                        i += list.size() - 1;
                                    }
                                    while (i != 0 && i + 1 == list.size());
                                } else {
                                    Attend attendRetur = new Attend();
                                    attendRetur.setNum("-1");
                                    attendRetur.setSwi("-1");
                                    status = "还未签到";
                                    time = DateFormat.getwyqStrTime(atime);
                                    attendRetur.setDateName(userDuty.getDutyDate());
                                    attendRetur.setAttendSetType(AttendSetType);
                                    attendRetur.setAttendStatus(attendStatus);
                                    attendRetur.setAtimestate(status);
                                    attendRetur.setCommute("1");
                                    attendRetur.setAddress(addres);
                                    attendRetur.setAtime(atime);
                                    attendRetur.setTime(time);
                                    attendRetur.setRemark(remark);
                                    workList.add(attendRetur);
                                }
                            }
                        }
                    }
                    if (workList.size() > 0) {
                        Attend attend = new Attend();
                        attend.setAttendList(workList);
                        resultList.add(attend);
                    }
                }
            }
            Attend attend = new Attend();
            attend.setList(resultList);
            attend.setSwitchList(attendSetList);
            wrappers.setFlag(true);
            wrappers.setStatus(true);
            wrappers.setData(attend);
            wrappers.setMsg("查询成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return wrappers;
    }


    //网页端个人考勤统计
    public BaseWrapper PersonalAttendance(String attendDate, HttpServletRequest req) throws ParseException {
        personalAttend(attendDate, req);
        Cookie redisSessionId = CookiesUtil.getCookieByName(req, "redisSessionId");
        String sqlType = "xoa" +SessionUtils.getSessionInfo(req.getSession(), "loginDateSouse", String.class, redisSessionId);
        Integer uid = SessionUtils.getSessionInfo(req.getSession(), Users.class, new Users(), redisSessionId).getUid();
        AttendSetWrappers wrappers = new AttendSetWrappers();
        Attend attend = new Attend();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("date", attendDate);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");

        List<Attend> attendlist = new ArrayList<Attend>();
        List<AttendSet> attendlist1 = new ArrayList<AttendSet>();


        Set<Date> datss = new HashSet<>();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
        SimpleDateFormat matter2 = new SimpleDateFormat("yyyy-MM-dd");
        Date dt = new Date();
        String a11 = df.format(dt);//获取当前日期
        String stratDate = "";
        String endDate = "";
        if (attendDate.equals(a11)) {
            stratDate = attendDate + "-01";
            endDate = matter2.format(dt);//获取当前日期时间

        } else {
            Date date1 = df.parse(attendDate);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date1);
            int last1 = calendar.getActualMaximum(calendar.DAY_OF_MONTH);    //获取本月最大天数
            stratDate = attendDate + "-01";
            endDate = attendDate + "-" + last1;
        }
        Date start1 = matter2.parse(stratDate);
        Date end1 = matter2.parse(endDate);
        Calendar c = Calendar.getInstance();

        List<Date> dates = DateCompute.getBetweenDates(start1, end1);
        //根据排版规则得到上班日期
        for (Date nowdate1 : dates) {
            c.setTime(nowdate1);
            int weekInt = c.get(Calendar.DAY_OF_WEEK);
            weekInt = weekInt - 1;
            if (weekInt == 0) {
                weekInt = 7;
            }
            AttendSet attendSet = null;
            UserDuty userDuty = userDutyMapper.userDuty(uid, matter2.format(nowdate1));
            if (userDuty != null) {
                attendSet = attendSetMapper.selectAttendSetSid(userDuty.getDutyType());
                if (attendSet != null) {
                    String week = String.valueOf(weekInt);
                    if (attendSet.getWorkdate().contains(week)) {
                        datss.add(nowdate1);
                    }
                }

            }
        }
        //获取节假日
        List<AttendHoliday> attendHolidays = holidayMapper.selectHoliday(new AttendHoliday());
        List<Date> das = new ArrayList<>();
        if (attendHolidays.size() > 0) {
            for (AttendHoliday a : attendHolidays) {
                Date beginDate = a.getBeginDate();
                Date endDate1 = a.getEndDate();
                List<Date> dates1 = findDates(beginDate, endDate1);
                das.addAll(dates1);
            }
        }
        Iterator<Date> iteator = datss.iterator();
        //去除节假日
        while (iteator.hasNext()) {
            Date next = iteator.next();
            for (Date date : das) {
                String com1 = new SimpleDateFormat("yyyy-MM-dd").format(next);
                String com2 = new SimpleDateFormat("yyyy-MM-dd").format(date);
                if (com1.equals(com2)) {
                    iteator.remove();
                    break;
                }
            }
        }
        //获取调休上班设置
        List<AttendExtraWork> extraworkSets = holidayMapper.getAttendExtraworkList();
        List<Date> extraWorkDates = new ArrayList<>();//加班天数
        if (extraworkSets.size() > 0) {
            for (AttendExtraWork e : extraworkSets) {
                String isContain = new SimpleDateFormat("yyyy-MM").format(e.getBeginDate());
                if (!attendDate.equals(isContain)) {
                    break;
                }
                Date beginDate = e.getBeginDate();
                String begDateStr = new SimpleDateFormat("yyyy-MM-dd").format(beginDate);
                Date endDate1 = e.getEndDate();
                String endDateStr = new SimpleDateFormat("yyyy-MM-dd").format(endDate1);
                List<Date> dates1 = findDates(beginDate, endDate1);
                extraWorkDates.addAll(dates1);
            }
        }
        Set<Date> difDates = new HashSet<>();
        //本月加班时间 （年-月-日）
        if (extraWorkDates.size() > 0) {
            for (Date date : extraWorkDates) {
                boolean flag = false;
                for (Date d : datss) {
                    flag = false;
                    String datecompr = new SimpleDateFormat("yyyy-MM-dd").format(date);
                    String sourceDate = new SimpleDateFormat("yyyy-MM-dd").format(d);
                    if (sourceDate.equals(datecompr)) {
                        flag = true;
                    }
                    if (!flag) {
                        difDates.add(date);
                    }
                }
            }
        }
        datss.addAll(difDates);
        Iterator<Date> iteators = datss.iterator();
        while (iteators.hasNext()) {
            Date next = iteators.next();
            if (next.getTime() > new Date().getTime()) {
                iteators.remove();
            }
        }

        if (datss != null && datss.size() > 0) {
            for (Date nowdate : datss) {
                List<Attend> workList = new ArrayList<Attend>();
                List<Attend> legwork = new ArrayList<Attend>();
                AttendSet attendSet = null;
                String aaaa = matter2.format(nowdate);
                UserDuty userDuty = userDutyMapper.userDuty(uid, matter2.format(nowdate));
                if (userDuty != null) {
                    attendSet = attendSetMapper.selectAttendSetSid(userDuty.getDutyType());
                    if (attendSet != null) {
                        String[] str1 = attendSet.getAtime1Set().split("\\|");
                        attendSet.setAtime1Setother(str1[0]);
                        attendSet.setCommute1(str1[1]);
                        String[] str2 = attendSet.getAtime2Set().split("\\|");
                        attendSet.setAtime2Setother(str2[0]);
                        attendSet.setCommute2(str2[1]);
                        String[] str3 = attendSet.getAtime3Set().split("\\|");
                        attendSet.setAtime3Setother(str3[0]);
                        attendSet.setCommute3(str3[1]);
                        String[] str4 = attendSet.getAtime4Set().split("\\|");
                        attendSet.setAtime4Setother(str4[0]);
                        attendSet.setCommute4(str4[1]);
                        String[] str5 = attendSet.getAtime5Set().split("\\|");
                        attendSet.setAtime5Setother(str5[0]);
                        attendSet.setCommute5(str5[1]);
                        String[] str6 = attendSet.getAtime6Set().split("\\|");
                        attendSet.setAtime6Setother(str6[0]);
                        attendSet.setCommute6(str6[1]);
                    }
                    if (numberOne.equals(attendSet.getAtime1Setother())) {
                        String attendStatus = numberZero;
                        String status = "";
                        int atime = 0;
                        String remark = "";
                        String addres = "";
                        Attend attend1 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberOne);
                        if (attend1 != null) {
                            if (numberOne.equals(attend1.getType())) {
                                if (numberOne.equals(attendSet.getCommute1())) {
                                    String a1 = DateFormat.getwyqStrTime(attend1.getAtime());
                                    if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime1()).getTime()) {
                                        status = "上班迟到";
                                        attendStatus = numberOne;
                                    } else {
                                        status = "上班正常";
                                        attendStatus = numberZero;
                                    }
                                } else {
                                    String a1 = DateFormat.getwyqStrTime(attend1.getAtime());
                                    if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime1()).getTime()) {
                                        status = "下班早退";
                                        attendStatus = "-1";
                                    } else {
                                        status = "下班正常";
                                        attendStatus = numberZero;
                                    }
                                }

                            }
                            atime = attend1.getAtime();
                            remark = attend1.getRemark();
                            addres = attend1.getAddress();

                        } else {
                            status = "未签到";
                            atime = 0;
                        }
                        Attend attend11 = new Attend();
                        attend11.setAttendStatus(attendStatus);
                        attend11.setNum(numberOne);
                        attend11.setSwi(numberOne);
                        attend11.setCommute(attendSet.getCommute1());
                        attend11.setAtime(atime);
                        attend11.setRemark(remark);
                        attend11.setAddress(addres);
                        attend11.setAtimestate(status);
                        if (DateFormat.getwyqStrTime(atime).equals(attendDate)) {
                            attend11.setTime("");
                        } else {
                            attend11.setTime(DateFormat.getwyqStrTime(atime));
                        }

                        attend11.setDateName(DateFormat.getDatestr(nowdate));
                        workList.add(attend11);

                    }
                    if (numberOne.equals(attendSet.getAtime2Setother())) {
                        String attendStatus = numberZero;
                        String status = "";
                        int atime = 0;
                        String remark = "";
                        String addres = "";
                        Attend attend2 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberTwo);
                        if (attend2 != null) {

                            if (numberTwo.equals(attend2.getType())) {

                                if (numberOne.equals(attendSet.getCommute2())) {
                                    String a1 = DateFormat.getwyqStrTime(attend2.getAtime());
                                    if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime2()).getTime()) {
                                        status = "上班迟到";
                                        attendStatus = numberOne;
                                    } else {
                                        status = "上班正常";
                                        attendStatus = numberZero;
                                    }
                                } else {
                                    String a1 = DateFormat.getwyqStrTime(attend2.getAtime());
                                    if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime2()).getTime()) {
                                        status = "下班早退";
                                        attendStatus = "-1";
                                    } else {
                                        status = "下班正常";
                                        attendStatus = numberZero;
                                    }
                                }

                            }
                            remark = attend2.getRemark();
                            addres = attend2.getAddress();
                            atime = attend2.getAtime();

                        } else {
                            status = "未签到";
                        }
                        Attend attend22 = new Attend();
                        attend22.setAttendStatus(attendStatus);
                        attend22.setNum(numberOne);
                        attend22.setSwi(numberOne);
                        attend22.setCommute(attendSet.getCommute2());
                        attend22.setAtime(atime);
                        attend22.setRemark(remark);
                        attend22.setAddress(addres);
                        attend22.setAtimestate(status);
                        if (DateFormat.getwyqStrTime(atime).equals(attendDate)) {
                            attend22.setTime("");
                        } else {
                            attend22.setTime(DateFormat.getwyqStrTime(atime));
                        }
                        attend22.setDateName(DateFormat.getDatestr(nowdate));
                        workList.add(attend22);


                    }
                    if (numberOne.equals(attendSet.getAtime3Setother())) {
                        String attendStatus = numberZero;
                        String status = "";
                        int atime = 0;
                        String remark = "";
                        String addres = "";
                        Attend attend3 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberThree);
                        if (attend3 != null) {

                            if (numberThree.equals(attend3.getType())) {

                                if (numberOne.equals(attendSet.getCommute3())) {
                                    String a1 = DateFormat.getwyqStrTime(attend3.getAtime());
                                    if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime3()).getTime()) {
                                        status = "上班迟到";
                                        attendStatus = numberOne;
                                    } else {
                                        status = "上班正常";
                                        attendStatus = numberZero;
                                    }
                                } else {
                                    String a1 = DateFormat.getwyqStrTime(attend3.getAtime());
                                    if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime3()).getTime()) {
                                        status = "下班早退";
                                        attendStatus = "-1";
                                    } else {
                                        status = "下班正常";
                                        attendStatus = numberZero;
                                    }
                                }

                            }
                            remark = attend3.getRemark();
                            addres = attend3.getAddress();
                            atime = attend3.getAtime();


                        } else {
                            status = "未签到";
                        }
                        Attend attend33 = new Attend();
                        attend33.setAttendStatus(attendStatus);
                        attend33.setNum(numberOne);
                        attend33.setSwi(numberOne);
                        attend33.setCommute(attendSet.getCommute3());
                        attend33.setAtime(atime);
                        attend33.setRemark(remark);
                        attend33.setAddress(addres);
                        attend33.setAtimestate(status);
                        if (DateFormat.getwyqStrTime(atime).equals(attendDate)) {
                            attend33.setTime("");
                        } else {
                            attend33.setTime(DateFormat.getwyqStrTime(atime));
                        }
                        //  attend33.setTime(DateFormat.getwyqStrTime(atime));
                        attend33.setDateName(DateFormat.getDatestr(nowdate));
                        workList.add(attend33);


                    }
                    if (numberOne.equals(attendSet.getAtime4Setother())) {
                        String attendStatus = numberZero;
                        String status = "";
                        int atime = 0;
                        String remark = "";
                        String addres = "";
                        Attend attend4 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberFour);
                        if (attend4 != null) {

                            if (numberFour.equals(attend4.getType())) {

                                if (numberOne.equals(attendSet.getCommute4())) {
                                    String a1 = DateFormat.getwyqStrTime(attend4.getAtime());
                                    if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime4()).getTime()) {
                                        status = "上班迟到";
                                        attendStatus = numberOne;
                                    } else {
                                        status = "上班正常";
                                        attendStatus = numberZero;
                                    }
                                } else {
                                    String a1 = DateFormat.getwyqStrTime(attend4.getAtime());
                                    if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime4()).getTime()) {
                                        status = "下班早退";
                                        attendStatus = "-1";
                                    } else {
                                        status = "下班正常";
                                        attendStatus = numberZero;
                                    }
                                }
                            }
                            remark = attend4.getRemark();
                            addres = attend4.getAddress();
                            atime = attend4.getAtime();
                        } else {
                            status = "未签到";
                        }
                        Attend attend44 = new Attend();
                        attend44.setAttendStatus(attendStatus);
                        attend44.setNum(numberOne);
                        attend44.setSwi(numberOne);
                        attend44.setCommute(attendSet.getCommute4());
                        attend44.setAtime(atime);
                        attend44.setRemark(remark);
                        attend44.setAddress(addres);
                        attend44.setAtimestate(status);
                        if (DateFormat.getwyqStrTime(atime).equals(attendDate)) {
                            attend44.setTime("");
                        } else {
                            attend44.setTime(DateFormat.getwyqStrTime(atime));
                        }
                        //  attend44.setTime(DateFormat.getwyqStrTime(atime));
                        attend44.setDateName(DateFormat.getDatestr(nowdate));
                        workList.add(attend44);

                    }

                    if (numberOne.equals(attendSet.getAtime5Setother())) {
                        String attendStatus = numberZero;
                        String status = "";
                        int atime = 0;
                        String remark = "";
                        String addres = "";
                        Attend attend5 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberFive);
                        if (attend5 != null) {

                            if (numberFive.equals(attend5.getType())) {

                                if (numberOne.equals(attendSet.getCommute5())) {
                                    String a1 = DateFormat.getwyqStrTime(attend5.getAtime());
                                    if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime5()).getTime()) {
                                        status = "上班迟到";
                                        attendStatus = numberOne;
                                    } else {
                                        status = "上班正常";
                                        attendStatus = numberZero;
                                    }
                                } else {
                                    String a1 = DateFormat.getwyqStrTime(attend5.getAtime());
                                    if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime5()).getTime()) {
                                        status = "下班早退";
                                        attendStatus = "-1";
                                    } else {
                                        status = "下班正常";
                                        attendStatus = numberZero;
                                    }
                                }
                            }
                            remark = attend5.getRemark();
                            addres = attend5.getAddress();
                            atime = attend5.getAtime();

                        } else {
                            status = "未签到";
                        }
                        Attend attend55 = new Attend();
                        attend55.setAttendStatus(attendStatus);
                        attend55.setNum(numberOne);
                        attend55.setSwi(numberOne);
                        attend55.setAtimestate(status);
                        attend55.setCommute(attendSet.getCommute5());
                        attend55.setRemark(remark);
                        attend55.setAddress(addres);
                        attend55.setAtime(atime);
                        if (DateFormat.getwyqStrTime(atime).equals(attendDate)) {
                            attend55.setTime("");
                        } else {
                            attend55.setTime(DateFormat.getwyqStrTime(atime));
                        }
                        attend55.setDateName(DateFormat.getDatestr(nowdate));
                        workList.add(attend55);


                    }

                    if (numberOne.equals(attendSet.getAtime6Setother())) {
                        String attendStatus = numberZero;
                        String status = "";
                        int atime = 0;
                        String remark = "";
                        String addres = "";
                        Attend attend6 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberSix);
                        if (attend6 != null) {

                            if (numberSix.equals(attend6.getType())) {

                                if (numberOne.equals(attendSet.getCommute6())) {
                                    String a1 = DateFormat.getwyqStrTime(attend6.getAtime());
                                    if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime6()).getTime()) {
                                        status = "上班迟到";
                                        attendStatus = numberOne;
                                    } else {
                                        status = "上班正常";
                                        attendStatus = numberZero;
                                    }
                                } else {
                                    String a1 = DateFormat.getwyqStrTime(attend6.getAtime());
                                    if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime6()).getTime()) {
                                        status = "下班早退";
                                        attendStatus = "-1";
                                    } else {
                                        status = "下班正常";
                                        attendStatus = numberZero;
                                    }
                                }
                            }
                            remark = attend6.getRemark();
                            addres = attend6.getAddress();
                            atime = attend6.getAtime();

                        } else {
                            status = "未签到";
                        }
                        Attend attend66 = new Attend();
                        attend66.setAttendStatus(attendStatus);
                        attend66.setNum(numberOne);
                        attend66.setSwi(numberOne);
                        attend66.setCommute(attendSet.getCommute6());
                        attend66.setRemark(remark);
                        attend66.setAddress(addres);
                        attend66.setAtime(atime);
                        if (DateFormat.getwyqStrTime(atime).equals(attendDate)) {
                            attend66.setTime("");
                        } else {
                            attend66.setTime(DateFormat.getwyqStrTime(atime));
                        }
                        attend66.setAtimestate(status);
                        attend66.setDateName(DateFormat.getDatestr(nowdate));

                        workList.add(attend66);

                    }


                    if (numberOne.equals(attendSet.getIsOut())) {
                        List<Attend> attend0 = attendMapper.selectAttend0(DateFormat.getDatestr(nowdate), uid);
                        if (attend0 != null && attend0.size() > 0) {
                            for (Attend a : attend0) {
                                if (StringUtils.checkNull(a.getFileId()) && StringUtils.checkNull(a.getFileName())) {
                                    a.setAttachment(GetAttachmentListUtil.returnAttachment(a.getFileName(), a.getFileName(), sqlType, GetAttachmentListUtil.MODULE_ATTEND));
                                }

                                legwork.add(a);

                            }

                        }

                    }

                }
                Attend attend1 = new Attend();
                attend1.setAttendList(workList);
                attend1.setLegwork(legwork);

                Format f = new SimpleDateFormat("yyyy-MM-dd");
                String format = f.format(nowdate);
                attendlist.add(attend1);
                attendlist1.add(attendSet);
            }
//                attendSet.getIsGo();
//                attendSet.getIsLeave();
//                attendSet.getIsTrip();
//                attendlist1.add(attendSet);

        }


        attend.setList(attendlist);
        attend.setSwitchList(attendlist1);
        wrappers.setFlag(true);
        wrappers.setStatus(true);
        wrappers.setData(attend);
        wrappers.setMsg("更新成功");


        return wrappers;


    }

    /**
     * 创建人：季佳伟
     * 创建时间：2017-11-20  下午4:30:17
     * 方法介绍：查询当天登录人的考勤状况
     * 参数说明：
     */
    public BaseWrapper PersonalTodayAttendance(String attendDate, HttpServletRequest req) throws ParseException {
        Cookie redisSessionId = CookiesUtil.getCookieByName(req, "redisSessionId");
        String sqlType = "xoa" +SessionUtils.getSessionInfo(req.getSession(), "loginDateSouse", String.class, redisSessionId);
        Integer uid = SessionUtils.getSessionInfo(req.getSession(), Users.class, new Users(), redisSessionId).getUid();
        AttendSetWrappers wrappers = new AttendSetWrappers();
        List<Attend> workList = new ArrayList<Attend>();
        UserExt userExt = userExtMapper.queryUserExt(uid);
        if (userExt != null) {
            for (int i = 1; i <= 6; i++) {
                Attend attend = attendMapper.selectAttendAll(attendDate, uid, i + "");
                if (attend != null) {
                    String time = DateFormat.getwyqStrTime(attend.getAtime());
                    attend.setTime(time);
                    workList.add(attend);
                }

            }
            wrappers.setFlag(true);
            wrappers.setStatus(true);
            wrappers.setData(workList);
            wrappers.setMsg("更新成功");
        }
        return wrappers;

    }

    /**
     * 创建人：季佳伟
     * 创建时间：2017-11-21  下午4:30:17
     * 方法介绍：查询登录人一段时间内的考勤状况
     * 参数说明：
     */
    public AttendSetWrappers AttendanceStatistics(String beginDate, String endDate, HttpServletRequest req) {
        AttendSetWrappers wrappers = new AttendSetWrappers();

        if (!StringUtils.checkNull(beginDate) && StringUtils.checkNull(endDate)) {
            Date date = DateFormat.getDate(beginDate + " 00:00:00");
            Calendar instance = Calendar.getInstance();
            instance.setTime(date);
            int actualMaximum = instance.getActualMaximum(Calendar.DAY_OF_MONTH);
            instance.set(Calendar.DAY_OF_MONTH, actualMaximum);
            endDate = instance.get(Calendar.YEAR) + "-" + (instance.get(Calendar.MONTH) + 1) + "-" + instance.get(Calendar.DAY_OF_MONTH);
        }

        Date dateTime = new Date();
        SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
        String time = format.format(dateTime);
        Date dateTime1 = new Date();
        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        String time1 = format1.format(dateTime1);
        Cookie redisSessionId = CookiesUtil.getCookieByName(req, "redisSessionId");
        Integer uid = SessionUtils.getSessionInfo(req.getSession(), Users.class, new Users(), redisSessionId).getUid();
        AttendStatistics attendStatistics = new AttendStatistics();
        List<Date> date = new ArrayList<Date>();
        UserExt userExt = userExtMapper.queryUserExt(uid);

        List<BaseAttend> normal = new ArrayList<BaseAttend>();//上班正常
        List<BaseAttend> normalyichang = new ArrayList<BaseAttend>();//设备异常
        List<BaseAttend> closed = new ArrayList<BaseAttend>();//下班正常
        List<BaseAttend> notSign = new ArrayList<BaseAttend>();//未签到
        List<BaseAttend> notOut = new ArrayList<BaseAttend>();//未签退
        List<BaseAttend> leaveEarly = new ArrayList<BaseAttend>();//早退
        List<BaseAttend> late = new ArrayList<BaseAttend>();//迟到
        List<BaseAttend> fields = new ArrayList<BaseAttend>();//外勤

        AttendSet attendSet = null;
        UserDuty userDuty = userDutyMapper.userDuty(uid, time1);
        if (userDuty != null) {
            attendSet = attendSetMapper.selectAttendSetSid(userDuty.getDutyType());

            int xqhbt = 0;
            String[] str1 = attendSet.getAtime1Set().split("\\|");
            if (numberOne.equals(str1[0])) {
                xqhbt++;
            }
            attendSet.setAtime1Setother(str1[0]);
            attendSet.setCommute1(str1[1]);
            String[] str2 = attendSet.getAtime2Set().split("\\|");
            if (numberOne.equals(str2[0])) {
                xqhbt++;
            }
            attendSet.setAtime2Setother(str2[0]);
            attendSet.setCommute2(str2[1]);
            String[] str3 = attendSet.getAtime3Set().split("\\|");
            if (numberOne.equals(str3[0])) {
                xqhbt++;
            }
            attendSet.setAtime3Setother(str3[0]);
            attendSet.setCommute3(str3[1]);
            String[] str4 = attendSet.getAtime4Set().split("\\|");
            if (numberOne.equals(str4[0])) {
                xqhbt++;
            }
            attendSet.setAtime4Setother(str4[0]);
            attendSet.setCommute4(str4[1]);
            String[] str5 = attendSet.getAtime5Set().split("\\|");
            if (numberOne.equals(str5[0])) {
                xqhbt++;
            }
            attendSet.setAtime5Setother(str5[0]);
            attendSet.setCommute5(str5[1]);
            String[] str6 = attendSet.getAtime6Set().split("\\|");
            if (numberOne.equals(str6[0])) {
                xqhbt++;
            }

            Calendar c = Calendar.getInstance();
            List<Date> dates = DateCompute.getBetweenDates(DateFormat.DateToStr(beginDate), DateFormat.DateToStr(endDate));
            for (Date nowdate1 : dates) {
                c.setTime(nowdate1);
                int weekInt = c.get(Calendar.DAY_OF_WEEK);
                weekInt = weekInt - 1;
                if (weekInt == 0) {
                    weekInt = 7;
                }

                String week = String.valueOf(weekInt);
                if (attendSet.getWorkdate().contains(week)) {
                    date.add(nowdate1);
                }
            }
            normalyichang = myAttendUnitException(beginDate, endDate, uid, req);
            for (Date nowdate : date) {
                if (numberOne.equals(attendSet.getIsOut())) {
                    List<Attend> attend0 = attendMapper.selectAttend0(DateFormat.getDatestr(nowdate), uid);
                    if (attend0 != null && attend0.size() > 0) {
                        Iterator<Attend> attendIterator = attend0.iterator();
                        while (attendIterator.hasNext()) {
                            Field field = new Field();//外勤
                            Attend attend1 = attendIterator.next();
                            field.setDate(DateFormat.getDatestrTime(nowdate));
                            field.setTime(DateFormat.getwyqStrTime(attend1.getAtime()));
                            field.setStr(attend1.getAddress());
                            field.setPhoneId(attend1.getPhoneId());
                            field.setCause(attend1.getRemark());
                            fields.add(field);
                        }
                    }

                }
                if (numberOne.equals(attendSet.getAtime1Setother())) {
                    String status = "";
                    if (DateFormat.getDateTimes(attendSet.getAtime1()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                        if (numberOne.equals(attendSet.getCommute1())) {
                            Attend attend1 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberOne);
                            if (attend1 != null) {

                                String a1 = DateFormat.getwyqStrTime(attend1.getAtime());
                                if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime1()).getTime()) {
                                    status = "迟到";
                                    BaseAttend latesix = new BaseAttend();

                                    latesix.setStr("签到时间为：" + attendSet.getAtime1() + "迟到(" + DateFormat.parseMillisecone(DateFormat.getDateTimes(a1).getTime() - DateFormat.getDateTimes(attendSet.getAtime1()).getTime()) + ") " + DateFormat.getDatestr(nowdate));


                                    late.add(latesix);
                                } else {
                                    status = "正常";
                                    BaseAttend normalB = new BaseAttend();
                                    normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend1.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                    normal.add(normalB);
                                }
                            } else {
                                status = "未签到";
                                BaseAttend notSignsix = new BaseAttend();
                                notSignsix.setStr("未签到(规定签到时间为：" + attendSet.getAtime1() + ") " + DateFormat.getDatestr(nowdate));
                                notSign.add(notSignsix);
                            }

                        } else {
                            Attend attend1 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberOne);
                            if (attend1 != null) {

                                String a1 = DateFormat.getwyqStrTime(attend1.getAtime());
                                if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime1()).getTime()) {
                                    status = "早退";
                                    BaseAttend leaveEarlysix = new BaseAttend();

                                    leaveEarlysix.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend1.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getDateTimes(attendSet.getAtime1()).getTime() - DateFormat.getDateTimes(a1).getTime()) + ") " + DateFormat.getDatestr(nowdate));

                                    leaveEarly.add(leaveEarlysix);
                                } else {
                                    status = "正常";
                                    BaseAttend closedB = new BaseAttend();
                                    closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend1.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                    closed.add(closedB);

                                }

                            } else {
                                status = "未签到";
                                BaseAttend notOutsix = new BaseAttend();
                                notOutsix.setStr("未签退(规定签到时间为：" + attendSet.getAtime1() + ") " + DateFormat.getDatestr(nowdate));
                                notOut.add(notOutsix);
                            }


                        }
                    }
                }
                if (numberOne.equals(attendSet.getAtime2Setother())) {
                    String status = "";
                    if (DateFormat.getDateTimes(attendSet.getAtime2()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                        if (numberOne.equals(attendSet.getCommute2())) {
                            Attend attend2 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberTwo);
                            if (attend2 != null) {

                                String a1 = DateFormat.getwyqStrTime(attend2.getAtime());
                                if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime2()).getTime()) {
                                    status = "迟到";
                                    BaseAttend latesix = new BaseAttend();

                                    latesix.setStr("签到时间为：" + attendSet.getAtime2() + "迟到(" + DateFormat.parseMillisecone(DateFormat.getDateTimes(a1).getTime() - DateFormat.getDateTimes(attendSet.getAtime2()).getTime()) + ") " + DateFormat.getDatestr(nowdate));


                                    late.add(latesix);
                                } else {
                                    status = "正常";
                                    BaseAttend normalB = new BaseAttend();
                                    normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend2.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                    normal.add(normalB);
                                }
                            } else {
                                status = "未签到";
                                BaseAttend notSignsix = new BaseAttend();
                                notSignsix.setStr("未签到(规定签到时间为：" + attendSet.getAtime2() + ") " + DateFormat.getDatestr(nowdate));
                                notSign.add(notSignsix);
                            }

                        } else {
                            Attend attend2 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberTwo);
                            if (attend2 != null) {

                                String a1 = DateFormat.getwyqStrTime(attend2.getAtime());
                                if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime2()).getTime()) {
                                    status = "早退";
                                    BaseAttend leaveEarlysix = new BaseAttend();

                                    leaveEarlysix.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend2.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getDateTimes(attendSet.getAtime2()).getTime() - DateFormat.getDateTimes(a1).getTime()) + ") " + DateFormat.getDatestr(nowdate));

                                    leaveEarly.add(leaveEarlysix);
                                } else {
                                    status = "正常";
                                    BaseAttend closedB = new BaseAttend();
                                    closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend2.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                    closed.add(closedB);

                                }

                            } else {
                                status = "未签到";
                                BaseAttend notOutsix = new BaseAttend();
                                notOutsix.setStr("未签退(规定签到时间为：" + attendSet.getAtime2() + ") " + DateFormat.getDatestr(nowdate));
                                notOut.add(notOutsix);
                            }


                        }
                    }
                }
                if (numberOne.equals(attendSet.getAtime3Setother())) {
                    String status = "";
                    if (DateFormat.getDateTimes(attendSet.getAtime3()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                        if (numberOne.equals(attendSet.getCommute3())) {
                            Attend attend3 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberThree);
                            if (attend3 != null) {

                                String a1 = DateFormat.getwyqStrTime(attend3.getAtime());
                                if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime3()).getTime()) {
                                    status = "迟到";
                                    BaseAttend latesix = new BaseAttend();

                                    latesix.setStr("签到时间为：" + attendSet.getAtime3() + "迟到(" + DateFormat.parseMillisecone(DateFormat.getDateTimes(a1).getTime() - DateFormat.getDateTimes(attendSet.getAtime3()).getTime()) + ") " + DateFormat.getDatestr(nowdate));


                                    late.add(latesix);
                                } else {
                                    status = "正常";
                                    BaseAttend normalB = new BaseAttend();
                                    normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend3.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                    normal.add(normalB);
                                }
                            } else {
                                status = "未签到";
                                BaseAttend notSignsix = new BaseAttend();
                                notSignsix.setStr("未签到(规定签到时间为：" + attendSet.getAtime3() + ") " + DateFormat.getDatestr(nowdate));
                                notSign.add(notSignsix);
                            }

                        } else {
                            Attend attend3 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberThree);
                            if (attend3 != null) {

                                String a1 = DateFormat.getwyqStrTime(attend3.getAtime());
                                if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime3()).getTime()) {
                                    status = "早退";
                                    BaseAttend leaveEarlysix = new BaseAttend();

                                    leaveEarlysix.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend3.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getDateTimes(attendSet.getAtime3()).getTime() - DateFormat.getDateTimes(a1).getTime()) + ") " + DateFormat.getDatestr(nowdate));

                                    leaveEarly.add(leaveEarlysix);
                                } else {
                                    status = "正常";
                                    BaseAttend closedB = new BaseAttend();
                                    closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend3.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                    closed.add(closedB);

                                }

                            } else {
                                status = "未签到";
                                BaseAttend notOutsix = new BaseAttend();
                                notOutsix.setStr("未签退(规定签到时间为：" + attendSet.getAtime3() + ") " + DateFormat.getDatestr(nowdate));
                                notOut.add(notOutsix);
                            }


                        }
                    }
                }
                if (numberOne.equals(attendSet.getAtime4Setother())) {
                    String status = "";
                    if (DateFormat.getDateTimes(attendSet.getAtime4()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                        if (numberOne.equals(attendSet.getCommute4())) {
                            Attend attend4 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberFour);
                            if (attend4 != null) {

                                String a1 = DateFormat.getwyqStrTime(attend4.getAtime());
                                if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime4()).getTime()) {
                                    status = "迟到";
                                    BaseAttend latesix = new BaseAttend();

                                    latesix.setStr("签到时间为：" + attendSet.getAtime4() + "迟到(" + DateFormat.parseMillisecone(DateFormat.getDateTimes(a1).getTime() - DateFormat.getDateTimes(attendSet.getAtime4()).getTime()) + ") " + DateFormat.getDatestr(nowdate));


                                    late.add(latesix);
                                } else {
                                    status = "正常";
                                    BaseAttend normalB = new BaseAttend();
                                    normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend4.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                    normal.add(normalB);
                                }
                            } else {
                                status = "未签到";
                                BaseAttend notSignsix = new BaseAttend();
                                notSignsix.setStr("未签到(规定签到时间为：" + attendSet.getAtime4() + ") " + DateFormat.getDatestr(nowdate));
                                notSign.add(notSignsix);
                            }

                        } else {
                            Attend attend4 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberFour);
                            if (attend4 != null) {

                                String a1 = DateFormat.getwyqStrTime(attend4.getAtime());
                                if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime4()).getTime()) {
                                    status = "早退";
                                    BaseAttend leaveEarlysix = new BaseAttend();

                                    leaveEarlysix.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend4.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getDateTimes(attendSet.getAtime4()).getTime() - DateFormat.getDateTimes(a1).getTime()) + ") " + DateFormat.getDatestr(nowdate));

                                    leaveEarly.add(leaveEarlysix);
                                } else {
                                    status = "正常";
                                    BaseAttend closedB = new BaseAttend();
                                    closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend4.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                    closed.add(closedB);

                                }

                            } else {
                                status = "未签到";
                                BaseAttend notOutsix = new BaseAttend();
                                notOutsix.setStr("未签退(规定签到时间为：" + attendSet.getAtime4() + ") " + DateFormat.getDatestr(nowdate));
                                notOut.add(notOutsix);
                            }


                        }
                    }
                }
                if (numberOne.equals(attendSet.getAtime5Setother())) {
                    String status = "";
                    if (DateFormat.getDateTimes(attendSet.getAtime5()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                        if (numberOne.equals(attendSet.getCommute5())) {
                            Attend attend5 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberFive);
                            if (attend5 != null) {

                                String a1 = DateFormat.getwyqStrTime(attend5.getAtime());
                                if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime5()).getTime()) {
                                    status = "迟到";
                                    BaseAttend latesix = new BaseAttend();

                                    latesix.setStr("签到时间为：" + attendSet.getAtime5() + "迟到(" + DateFormat.parseMillisecone(DateFormat.getDateTimes(a1).getTime() - DateFormat.getDateTimes(attendSet.getAtime5()).getTime()) + ") " + DateFormat.getDatestr(nowdate));


                                    late.add(latesix);
                                } else {
                                    status = "正常";
                                    BaseAttend normalB = new BaseAttend();
                                    normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend5.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                    normal.add(normalB);
                                }
                            } else {
                                status = "未签到";
                                BaseAttend notSignsix = new BaseAttend();
                                notSignsix.setStr("未签到(规定签到时间为：" + attendSet.getAtime5() + ") " + DateFormat.getDatestr(nowdate));
                                notSign.add(notSignsix);
                            }

                        } else {
                            Attend attend5 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberFive);
                            if (attend5 != null) {

                                String a1 = DateFormat.getwyqStrTime(attend5.getAtime());
                                if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime5()).getTime()) {
                                    status = "早退";
                                    BaseAttend leaveEarlysix = new BaseAttend();

                                    leaveEarlysix.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend5.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getDateTimes(attendSet.getAtime5()).getTime() - DateFormat.getDateTimes(a1).getTime()) + ") " + DateFormat.getDatestr(nowdate));

                                    leaveEarly.add(leaveEarlysix);
                                } else {
                                    status = "正常";
                                    BaseAttend closedB = new BaseAttend();
                                    closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend5.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                    closed.add(closedB);

                                }

                            } else {
                                status = "未签到";
                                BaseAttend notOutsix = new BaseAttend();
                                notOutsix.setStr("未签退(规定签到时间为：" + attendSet.getAtime5() + ") " + DateFormat.getDatestr(nowdate));
                                notOut.add(notOutsix);
                            }


                        }
                    }
                }
                if (numberOne.equals(attendSet.getAtime6Setother())) {
                    String status = "";
                    if (DateFormat.getDateTimes(attendSet.getAtime6()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                        if (numberOne.equals(attendSet.getCommute6())) {
                            Attend attend6 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberSix);
                            if (attend6 != null) {

                                String a1 = DateFormat.getwyqStrTime(attend6.getAtime());
                                if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime6()).getTime()) {
                                    status = "迟到";
                                    BaseAttend latesix = new BaseAttend();

                                    latesix.setStr("签到时间为：" + attendSet.getAtime6() + "迟到(" + DateFormat.parseMillisecone(DateFormat.getDateTimes(a1).getTime() - DateFormat.getDateTimes(attendSet.getAtime6()).getTime()) + ") " + DateFormat.getDatestr(nowdate));


                                    late.add(latesix);
                                } else {
                                    status = "正常";
                                    BaseAttend normalB = new BaseAttend();
                                    normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend6.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                    normal.add(normalB);
                                }
                            } else {
                                status = "未签到";
                                BaseAttend notSignsix = new BaseAttend();
                                notSignsix.setStr("未签到(规定签到时间为：" + attendSet.getAtime6() + ") " + DateFormat.getDatestr(nowdate));
                                notSign.add(notSignsix);
                            }

                        } else {
                            Attend attend6 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberSix);
                            if (attend6 != null) {

                                String a1 = DateFormat.getwyqStrTime(attend6.getAtime());
                                if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime6()).getTime()) {
                                    status = "早退";
                                    BaseAttend leaveEarlysix = new BaseAttend();

                                    leaveEarlysix.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend6.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getDateTimes(attendSet.getAtime6()).getTime() - DateFormat.getDateTimes(a1).getTime()) + ") " + DateFormat.getDatestr(nowdate));

                                    leaveEarly.add(leaveEarlysix);
                                } else {
                                    status = "正常";
                                    BaseAttend closedB = new BaseAttend();
                                    closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend6.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                    closed.add(closedB);

                                }

                            } else {
                                status = "weiqiandao";
                                BaseAttend notOutsix = new BaseAttend();
                                notOutsix.setStr("未签退(规定签到时间为：" + attendSet.getAtime6() + ")" + DateFormat.getDatestr(nowdate));
                                notOut.add(notOutsix);
                            }


                        }
                    }
                }
            }


            attendStatistics.setCount1(normal.size());
            attendStatistics.setCount1List(normal);//上班正常

            attendStatistics.setCount2(closed.size());
            attendStatistics.setCount2List(closed);//下班正常

            attendStatistics.setCount3(notSign.size());
            attendStatistics.setCount3List(notSign);//未签到

            attendStatistics.setCount4(notOut.size());
            attendStatistics.setCount4List(notOut);//未签退

            attendStatistics.setCount5(late.size());
            attendStatistics.setCount5List(late);//迟到

            attendStatistics.setCount6(leaveEarly.size());
            attendStatistics.setCount6List(leaveEarly);//早退

            attendStatistics.setCount7(normalyichang.size());
            attendStatistics.setCount7List(normalyichang);//異常

            attendStatistics.setCount8(fields.size());
            attendStatistics.setCount8List(fields);//外勤


        }

        if (attendStatistics != null) {
            wrappers.setFlag(true);
            wrappers.setStatus(true);
            wrappers.setData(attendStatistics);
            wrappers.setMsg("更新成功");
        } else {
            wrappers.setFlag(false);
            wrappers.setStatus(true);
            wrappers.setMsg("更新失敗");
        }
        return wrappers;
    }

    //考勤统计查询接口
    public AttendSetWrappers pcAttendanceStatistics(String beiginDate, String endDate, String deptId, String dutyType,
                                                    String uids, HttpServletRequest req) {
        AttendSetWrappers wrappers = new AttendSetWrappers();
        if (endDate == null) {
            endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        }
        if (beiginDate == null) {
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DATE, -7);
            beiginDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());

        }
        Map<String, Object> objectMap = new HashMap<String, Object>();
        //部门id
        objectMap.put("deptId", deptId);
        //考勤类型
        objectMap.put("dutyType", dutyType);
        //用户id
        objectMap.put("uid", uids);
        // 通过deptId dutyType uid   来查询三个表的信息  department , user ,user_ext
        List<Users> usersList = usersMapper.getUsersByMaps(objectMap);
        Iterator<Users> usersIterator = usersList.iterator();
        Date dateTime = new Date();
        SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
        String time = format.format(dateTime);
        Date dateTime1 = new Date();
        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        String time1 = format1.format(dateTime1);

        List<AttendStatistics> attendStatisticAll = new ArrayList<>();
        while (usersIterator.hasNext()) {
            List<Date> date = new ArrayList<Date>();
            Users users = usersIterator.next();

            Integer uid = users.getUid();

            Long timeDifference = (long) 0; //加班时长统计
            int dutyCount = 0; //值班天数统计
            List<BaseAttend> normal = new ArrayList<BaseAttend>();//上班正常
            List<BaseAttend> normalyichang = new ArrayList<BaseAttend>();//设备异常
            List<BaseAttend> closed = new ArrayList<BaseAttend>();//下班正常
            List<BaseAttend> notSign = new ArrayList<BaseAttend>();//未签到
            List<BaseAttend> notOut = new ArrayList<BaseAttend>();//未签退
            List<BaseAttend> leaveEarly = new ArrayList<BaseAttend>();//早退
            List<BaseAttend> late = new ArrayList<BaseAttend>();//迟到
            List<BaseAttend> fields = new ArrayList<BaseAttend>();//外勤
            List<BaseAttend> attendance = new ArrayList<BaseAttend>();//加班
            List<BaseAttend> evection = new ArrayList<BaseAttend>();//出差
            List<BaseAttend> leave = new ArrayList<BaseAttend>();//请假
            List<BaseAttend> out = new ArrayList<BaseAttend>();//外出
            List<BaseAttend> overTime = new ArrayList<BaseAttend>();//加班时长
            List<BaseAttend> duty = new ArrayList<BaseAttend>();//值班时长

            AttendSet attendSet = null;
            UserDuty userDuty = userDutyMapper.userDuty(uid, time1);
            if (userDuty != null) {
                attendSet = attendSetMapper.selectAttendSetSid(userDuty.getDutyType());

                int xqhbt = 0;
                //第一次签到开关
                if (attendSet != null) {
                    String[] str1 = attendSet.getAtime1Set().split("\\|");
                    if (numberOne.equals(str1[0])) {
                        xqhbt++;
                    }
                    //第一次签到开关
                    attendSet.setAtime1Setother(str1[0]);
                    //第一次上下班开关
                    attendSet.setCommute1(str1[1]);
                    String[] str2 = attendSet.getAtime2Set().split("\\|");
                    if (numberOne.equals(str2[0])) {
                        xqhbt++;
                    }
                    attendSet.setAtime2Setother(str2[0]);
                    attendSet.setCommute2(str2[1]);
                    String[] str3 = attendSet.getAtime3Set().split("\\|");
                    if (numberOne.equals(str3[0])) {
                        xqhbt++;
                    }
                    attendSet.setAtime3Setother(str3[0]);
                    attendSet.setCommute3(str3[1]);
                    String[] str4 = attendSet.getAtime4Set().split("\\|");
                    if (numberOne.equals(str4[0])) {
                        xqhbt++;
                    }


                    attendSet.setAtime4Setother(str4[0]);
                    attendSet.setCommute4(str4[1]);
                    String[] str5 = attendSet.getAtime5Set().split("\\|");
                    if (numberOne.equals(str5[0])) {
                        xqhbt++;
                    }
                    attendSet.setAtime5Setother(str5[0]);
                    attendSet.setCommute5(str5[1]);
                    String[] str6 = attendSet.getAtime6Set().split("\\|");
                    if (numberOne.equals(str6[0])) {
                        xqhbt++;
                    }


                    Calendar c = Calendar.getInstance();
                    List<Date> dates = DateCompute.getBetweenDates(DateFormat.DateToStr(beiginDate), DateFormat.DateToStr(endDate));
                    for (Date nowdate1 : dates) {
                        c.setTime(nowdate1);
                        int weekInt = c.get(Calendar.DAY_OF_WEEK);
                        weekInt = weekInt - 1;
                        if (weekInt == 0) {
                            weekInt = 7;
                        }

                        String week = String.valueOf(weekInt);
                        if (attendSet.getWorkdate().contains(week)) {
                            date.add(nowdate1);
                        }
                    }
                    normalyichang = myAttendUnitException(beiginDate, endDate, uid, req);

                    for (Date nowdate : date) {
                        if (numberOne.equals(attendSet.getIsOut())) {
                            List<Attend> attend0 = attendMapper.selectAttend0(DateFormat.getDatestr(nowdate), uid);
                            if (attend0 != null && attend0.size() > 0) {
                                Iterator<Attend> attendIterator = attend0.iterator();
                                while (attendIterator.hasNext()) {
                                    Field field = new Field();//外勤
                                    Attend attend1 = attendIterator.next();
                                    field.setDate(DateFormat.getDatestrTime(nowdate));
                                    field.setTime(DateFormat.getwyqStrTime(attend1.getAtime()));
                                    field.setStr(attend1.getAddress());
                                    field.setPhoneId(attend1.getPhoneId());
                                    field.setCause(attend1.getRemark());
                                    fields.add(field);
                                }
                            }

                        }

                        if (numberOne.equals(attendSet.getIsDuty())) {
                            Attend attendcount = attendMapper.getAttendDetailByType(String.valueOf(users.getUid()), "9", DateFormat.getDatestr(nowdate));
                            if (attendcount != null) {
                                dutyCount++;
                            }
                        }
                        if (numberOne.equals(attendSet.getIsOvertime())) { //加班
                            Attend begin = attendMapper.getAttendDetailByType(String.valueOf(users.getUid()), "7", DateFormat.getDatestr(nowdate));
                            Attend end = attendMapper.getAttendDetailByType(String.valueOf(users.getUid()), "8", DateFormat.getDatestr(nowdate));
                            if (begin != null && end != null) {
                                Integer startTime = begin.getAtime();
                                String beginDate = new SimpleDateFormat("yyyy-MM-dd").format(begin.getDate()) + " " + new SimpleDateFormat(" HH:mm:ss").format(Long.valueOf(startTime));
                                Integer enddate = end.getAtime();
                                String jieshu = new SimpleDateFormat("yyyy-MM-dd").format(end.getDate()) + " " + new SimpleDateFormat(" HH:mm:ss").format(Long.valueOf(enddate));
                                try {
                                    timeDifference += getTimeDifference(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(beginDate), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(jieshu));
                                } catch (ParseException e) {
                                    e.printStackTrace();
                                }
                            }

                        }

                        if (numberOne.equals(attendSet.getAtime1Setother())) {
                            String status = "";
                            if (DateFormat.getDateTimes(attendSet.getAtime1()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                                if (numberOne.equals(attendSet.getCommute1())) {
                                    Attend attend1 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberOne);
                                    if (attend1 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend1.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime1()).getTime()) {
                                            status = "迟到";
                                            BaseAttend latesix = new BaseAttend();

                                            latesix.setStr("签到时间为：" + attendSet.getAtime1() + "迟到(" + DateFormat.parseMillisecone(attend1.getAtime() - DateFormat.getWYQTime(attendSet.getAtime1())) + ")");


                                            late.add(latesix);
                                        } else {
                                            status = "正常";
                                            BaseAttend normalB = new BaseAttend();
                                            normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend1.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                            normal.add(normalB);
                                        }
                                    } else {
                                        status = "未签到";
                                        BaseAttend notSignsix = new BaseAttend();
                                        notSignsix.setStr("未签到(规定签到时间为：" + attendSet.getAtime1() + ")");
                                        notSign.add(notSignsix);
                                    }

                                } else {
                                    Attend attend1 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberOne);
                                    if (attend1 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend1.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime1()).getTime()) {
                                            status = "早退";
                                            BaseAttend leaveEarlysix = new BaseAttend();

                                            leaveEarlysix.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend1.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime1()) - attend1.getAtime()) + ")");

                                            leaveEarly.add(leaveEarlysix);
                                        } else {
                                            status = "正常";
                                            BaseAttend closedB = new BaseAttend();
                                            closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend1.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                            closed.add(closedB);

                                        }

                                    } else {
                                        status = "未签到";
                                        BaseAttend notOutsix = new BaseAttend();
                                        notOutsix.setStr("未签退(规定签到时间为：" + attendSet.getAtime1() + ")");
                                        notOut.add(notOutsix);
                                    }


                                }
                            }
                        }
                        if (numberOne.equals(attendSet.getAtime2Setother())) {
                            String status = "";
                            if (DateFormat.getDateTimes(attendSet.getAtime2()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                                if (numberOne.equals(attendSet.getCommute2())) {
                                    Attend attend2 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberTwo);
                                    if (attend2 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend2.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime2()).getTime()) {
                                            status = "迟到";
                                            BaseAttend latesix = new BaseAttend();

                                            latesix.setStr("签到时间为：" + attendSet.getAtime2() + "迟到(" + DateFormat.parseMillisecone(attend2.getAtime() - DateFormat.getWYQTime(attendSet.getAtime2())) + ")");


                                            late.add(latesix);
                                        } else {
                                            status = "正常";
                                            BaseAttend normalB = new BaseAttend();
                                            normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend2.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                            normal.add(normalB);
                                        }
                                    } else {
                                        status = "未签到";
                                        BaseAttend notSignsix = new BaseAttend();
                                        notSignsix.setStr("未签到(规定签到时间为：" + attendSet.getAtime2() + ")");
                                        notSign.add(notSignsix);
                                    }

                                } else {
                                    Attend attend2 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberTwo);
                                    if (attend2 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend2.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime2()).getTime()) {
                                            status = "早退";
                                            BaseAttend leaveEarlysix = new BaseAttend();

                                            leaveEarlysix.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend2.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime2()) - attend2.getAtime()) + ")");

                                            leaveEarly.add(leaveEarlysix);
                                        } else {
                                            status = "正常";
                                            BaseAttend closedB = new BaseAttend();
                                            closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend2.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                            closed.add(closedB);

                                        }

                                    } else {
                                        status = "未签到";
                                        BaseAttend notOutsix = new BaseAttend();
                                        notOutsix.setStr("未签退(规定签到时间为：" + attendSet.getAtime2() + ")");
                                        notOut.add(notOutsix);
                                    }


                                }
                            }
                        }
                        if (numberOne.equals(attendSet.getAtime3Setother())) {
                            String status = "";
                            if (DateFormat.getDateTimes(attendSet.getAtime3()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                                if (numberOne.equals(attendSet.getCommute3())) {
                                    Attend attend3 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberThree);
                                    if (attend3 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend3.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime3()).getTime()) {
                                            status = "迟到";
                                            BaseAttend latesix = new BaseAttend();

                                            latesix.setStr("签到时间为：" + attendSet.getAtime3() + "迟到(" + DateFormat.parseMillisecone(attend3.getAtime() - DateFormat.getWYQTime(attendSet.getAtime3())) + ")");


                                            late.add(latesix);
                                        } else {
                                            status = "正常";
                                            BaseAttend normalB = new BaseAttend();
                                            normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend3.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                            normal.add(normalB);
                                        }
                                    } else {
                                        status = "未签到";
                                        BaseAttend notSignsix = new BaseAttend();
                                        notSignsix.setStr("未签到(规定签到时间为：" + attendSet.getAtime3() + ")");
                                        notSign.add(notSignsix);
                                    }

                                } else {
                                    Attend attend3 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberThree);
                                    if (attend3 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend3.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime3()).getTime()) {
                                            status = "早退";
                                            BaseAttend leaveEarlysix = new BaseAttend();

                                            leaveEarlysix.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend3.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime3()) - attend3.getAtime()) + ")");

                                            leaveEarly.add(leaveEarlysix);
                                        } else {
                                            status = "正常";
                                            BaseAttend closedB = new BaseAttend();
                                            closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend3.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                            closed.add(closedB);

                                        }

                                    } else {
                                        status = "未签到";
                                        BaseAttend notOutsix = new BaseAttend();
                                        notOutsix.setStr("未签退(规定签到时间为：" + attendSet.getAtime3() + ")");
                                        notOut.add(notOutsix);
                                    }


                                }
                            }
                        }
                        if (numberOne.equals(attendSet.getAtime4Setother())) {
                            String status = "";
                            if (DateFormat.getDateTimes(attendSet.getAtime4()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                                if (numberOne.equals(attendSet.getCommute4())) {
                                    Attend attend4 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberFour);
                                    if (attend4 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend4.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime4()).getTime()) {
                                            status = "迟到";
                                            BaseAttend latesix = new BaseAttend();

                                            latesix.setStr("签到时间为：" + attendSet.getAtime4() + "迟到(" + DateFormat.parseMillisecone(attend4.getAtime() - DateFormat.getWYQTime(attendSet.getAtime4())) + ")");


                                            late.add(latesix);
                                        } else {
                                            status = "正常";
                                            BaseAttend normalB = new BaseAttend();
                                            normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend4.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                            normal.add(normalB);
                                        }
                                    } else {
                                        status = "未签到";
                                        BaseAttend notSignsix = new BaseAttend();
                                        notSignsix.setStr("未签到(规定签到时间为：" + attendSet.getAtime4() + ")");
                                        notSign.add(notSignsix);
                                    }

                                } else {
                                    Attend attend4 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberFour);
                                    if (attend4 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend4.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime4()).getTime()) {
                                            status = "早退";
                                            BaseAttend leaveEarlysix = new BaseAttend();

                                            leaveEarlysix.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend4.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime4()) - attend4.getAtime()) + ")");

                                            leaveEarly.add(leaveEarlysix);
                                        } else {
                                            status = "正常";
                                            BaseAttend closedB = new BaseAttend();
                                            closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend4.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                            closed.add(closedB);

                                        }

                                    } else {
                                        status = "未签到";
                                        BaseAttend notOutsix = new BaseAttend();
                                        notOutsix.setStr("未签退(规定签到时间为：" + attendSet.getAtime4() + ")");
                                        notOut.add(notOutsix);
                                    }


                                }
                            }
                        }
                        if (numberOne.equals(attendSet.getAtime5Setother())) {
                            String status = "";
                            if (DateFormat.getDateTimes(attendSet.getAtime5()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                                if (numberOne.equals(attendSet.getCommute5())) {
                                    Attend attend5 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberFive);
                                    if (attend5 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend5.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime5()).getTime()) {
                                            status = "迟到";
                                            BaseAttend latesix = new BaseAttend();

                                            latesix.setStr("签到时间为：" + attendSet.getAtime5() + "迟到(" + DateFormat.parseMillisecone(attend5.getAtime() - DateFormat.getWYQTime(attendSet.getAtime5())) + ")");
                                            latesix.setSignStatus(status);
                                            latesix.setSignTimeStr("规定签到时间为：" + attendSet.getAtime5() + "签到时间：(" + DateFormat.parseMillisecone(attend5.getAtime()) + ")");

                                            late.add(latesix);
                                        } else {
                                            status = "正常";
                                            BaseAttend normalB = new BaseAttend();
                                            normalB.setSignStatus(status);
                                            normalB.setSignTimeStr("规定签到时间为：" + attendSet.getAtime5() + "签到时间：(" + DateFormat.parseMillisecone(attend5.getAtime()) + ")");

                                            normal.add(normalB);
                                        }
                                    } else {
                                        status = "未签到";
                                        BaseAttend notSignsix = new BaseAttend();
                                        notSignsix.setSignStatus(status);
                                        notSignsix.setStr("未签到(规定签到时间为：" + attendSet.getAtime5() + ")");
                                        notSign.add(notSignsix);
                                    }

                                } else {
                                    Attend attend5 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberFive);
                                    if (attend5 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend5.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime5()).getTime()) {
                                            status = "早退";
                                            BaseAttend leaveEarlysix = new BaseAttend();
                                            leaveEarlysix.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend5.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime5()) - attend5.getAtime()) + ")");

                                            leaveEarly.add(leaveEarlysix);
                                        } else {
                                            status = "正常";
                                            BaseAttend closedB = new BaseAttend();
                                            closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend5.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                            closed.add(closedB);

                                        }

                                    } else {
                                        status = "未签到";
                                        BaseAttend notOutsix = new BaseAttend();
                                        notOutsix.setStr("未签退(规定签到时间为：" + attendSet.getAtime5() + ")");
                                        notOut.add(notOutsix);
                                    }


                                }
                            }
                        }
                        if (numberOne.equals(attendSet.getAtime6Setother())) {
                            String status = "";
                            if (DateFormat.getDateTimes(attendSet.getAtime6()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                                if (numberOne.equals(attendSet.getCommute6())) {
                                    Attend attend6 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberSix);
                                    if (attend6 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend6.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime6()).getTime()) {
                                            status = "迟到";
                                            BaseAttend latesix = new BaseAttend();

                                            latesix.setStr("签到时间为：" + attendSet.getAtime6() + "迟到(" + DateFormat.parseMillisecone(attend6.getAtime() - DateFormat.getWYQTime(attendSet.getAtime6())) + ")");


                                            late.add(latesix);
                                        } else {
                                            status = "正常";
                                            BaseAttend normalB = new BaseAttend();
                                            normalB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend6.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                            normal.add(normalB);
                                        }
                                    } else {
                                        status = "未签到";
                                        BaseAttend notSignsix = new BaseAttend();
                                        notSignsix.setStr("未签到(规定签到时间为：" + attendSet.getAtime6() + ")");
                                        notSign.add(notSignsix);
                                    }

                                } else {
                                    Attend attend6 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberSix);
                                    if (attend6 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend6.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime6()).getTime()) {
                                            status = "早退";
                                            BaseAttend leaveEarlysix = new BaseAttend();

                                            leaveEarlysix.setStr("签到时间为：" + DateFormat.getwyqStrTime(attend6.getAtime()) + "早退(" + DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime6()) - attend6.getAtime()) + ")");

                                            leaveEarly.add(leaveEarlysix);
                                        } else {
                                            status = "正常";
                                            BaseAttend closedB = new BaseAttend();
                                            closedB.setStr("签到时间：" + DateFormat.getwyqStrTime(attend6.getAtime())/*+"迟到"+DateFormat.getwyqStrTime(i2)*/);
                                            closed.add(closedB);

                                        }

                                    } else {
                                        status = "weiqiandao";
                                        BaseAttend notOutsix = new BaseAttend();
                                        notOutsix.setStr("未签退(规定签到时间为：" + attendSet.getAtime6() + ")");
                                        notOut.add(notOutsix);
                                    }


                                }
                            }
                        }
                    }
                }

                AttendStatistics attendStatistics = new AttendStatistics();
                attendStatistics.setUserName(users.getUserName());

                attendStatistics.setDeptName(users.getDeptName());

                attendStatistics.setUid(users.getUid());

                attendStatistics.setCount1(normal.size());
                attendStatistics.setCount1List(normal);//上班正常

                attendStatistics.setCount2(closed.size());
                attendStatistics.setCount2List(closed);//下班正常

                attendStatistics.setCount3(notSign.size());
                attendStatistics.setCount3List(notSign);//未签到

                attendStatistics.setCount4(notOut.size());
                attendStatistics.setCount4List(notOut);//未签退

                attendStatistics.setCount5(late.size());
                attendStatistics.setCount5List(late);//迟到

                attendStatistics.setCount6(leaveEarly.size());
                attendStatistics.setCount6List(leaveEarly);//早退

                attendStatistics.setCount7(normalyichang.size());
                attendStatistics.setCount7List(normalyichang);//異常

                attendStatistics.setCount8(fields.size());
                attendStatistics.setCount8List(fields);//外勤

                attendStatistics.setCount9(Integer.parseInt(String.valueOf(timeDifference)));
                attendStatistics.setCount9List(attendance);//加班

                attendStatistics.setCount10(dutyCount); //值班天数
                attendStatistics.setCount10List(evection);//出差

                attendStatistics.setCount11(leave.size());
                attendStatistics.setCount11List(leave);//请假

                attendStatistics.setCount12(out.size());
                attendStatistics.setCount12List(out);//外出

                attendStatisticAll.add(attendStatistics);

            }
        }
        if (attendStatisticAll.size() > 0) {
            wrappers.setFlag(true);
            wrappers.setStatus(true);
            wrappers.setData(attendStatisticAll);
            wrappers.setMsg("查询成功");
        } else {
            wrappers.setFlag(false);
            wrappers.setStatus(true);
            wrappers.setMsg("查询失败");
        }
        return wrappers;
    }


    ///根据ID 查询该用户签到的所有时间
    public ToJson selectAttendDate(Integer uid) {

        ToJson toJson = new ToJson();
        List<Date> dateList = attendMapper.selectAttendDate(uid);
        List<Map<String, Object>> list = new ArrayList<>();

        for (Date date : dateList) {
            Map<String, Object> map = new LinkedHashMap<String, Object>();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String date2 = simpleDateFormat.format(date);
            map.put("date2", date2);

            SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
            String date3 = simpleDateFormat1.format(new Date());

            list.add(map);
        }
        if (list != null) {

            toJson.setFlag(0);
            toJson.setMsg("查询成功");
            toJson.setObj(list);
        } else {
            toJson.setFlag(0);
            toJson.setMsg("日期为空");
        }

        return toJson;
    }

    /**
     * 考勤详情
     * 左春晖 18-4-26  14:21
     *
     * @param stratDate
     * @param endDate
     * @param uid
     * @return
     */
    public ToJson selectAttendParticulars(String stratDate, String endDate, Integer uid) {
        ToJson<Attend> json = new ToJson<>();
        Map<String, Object> map = new HashMap<>();
        map.put("date1", stratDate);
        map.put("date2", endDate);
        map.put("uid", uid);
        try {
            SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
            String newdate = simpleDateFormat1.format(new Date());
            List<Attend> list = attendMapper.selectAttendParticulars(map);
            AttendSet attendSets = null;
            UserDuty userDuty = userDutyMapper.userDuty(uid, newdate);
            if (userDuty != null) {
                attendSets = attendSetMapper.selectAttendSetSid(userDuty.getDutyType());
            } else {
                attendSets = attendSetMapper.selectAttendSetSid(99);
            }
            List<Attend> attendb = new ArrayList<>();
            Map<String, Object> maps = new HashMap<>();
            maps.put("uid", uid);
            Long timeDifference = (long) 0;
            for (Attend attend : list) {
                Attend attenda = new Attend();
                String state = "";//签到状态
                String watate = "";//外勤签到
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String date = simpleDateFormat.format(attend.getDate());
                String atime1 = DateFormat.getwyqStrTime(attend.getAtime());
                if (attend.getType().equals("0")) {
                    attenda.setTime(atime1);
                    state = "外勤";
                }
                if (attend.getType().equals("7")) {

                    if (attend.getAtime() == null) {
                        state = "未签到";
                    } else {
                        maps.put("date", attend.getDate());
                        maps.put("type", 8);
                        Attend attendByType = attendMapper.getAttendByType(maps);
                        Integer startTime = attend.getAtime();
                        String beginDate = new SimpleDateFormat("yyyy-MM-dd").format(attend.getDate()) + " " + new SimpleDateFormat(" HH:mm:ss").format(Long.valueOf(startTime));
                        if (attendByType != null) {
                            Integer enddate = attendByType.getAtime();
                            String jieshu = new SimpleDateFormat("yyyy-MM-dd").format(attendByType.getDate()) + " " + new SimpleDateFormat(" HH:mm:ss").format(Long.valueOf(enddate));

                            try {
                                timeDifference += getTimeDifference(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(beginDate), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(jieshu));
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }
                            attenda.setTime(timeDifference + "小时");
                            //attenda.setDateStr(timeDifference);
                            state = "加班";
                        } else {
                            continue;
                        }


                    }
                }
                if (attend.getType().equals("8")) {
                    continue;
                }
                if (attend.getType().equals("9")) {
                    attenda.setTime(atime1);
                    if (attend.getAtime() == null) {
                        state = "未签到";
                    } else {
                        state = "值班";
                    }
                }
                if (attend.getType().equals("10")) {
                    continue;
                }
                if (attend.getType().equals("1")) {
                    attenda.setTime(atime1);
                    if (attend.getAtime() == null) {
                        state = "未签到";
                    } else {
                        if ((this.reTime(attend.getAtime()).intValue()) < (DateFormat.getWYQTime(attendSets.getAtime1()))) {
                            state = "正常";
                        } else if ((attend.getAtime()) > (DateFormat.getWYQTime(attendSets.getAtime1()))) {
                            state = "迟到";
                        }
                    }
                }
                if (attend.getType().equals("2")) {
                    attenda.setTime(atime1);
                    if (attend.getAtime() == null && attend.getAtime() == 0) {
                        state = "未签退";
                    } else {
                        if ((attend.getAtime()) > (DateFormat.getWYQTime(attendSets.getAtime2()))) {
                            state = "正常";
                        } else if ((this.reTime(attend.getAtime()).intValue()) < (DateFormat.getWYQTime(attendSets.getAtime2()))) {
                            state = "早退";
                        }
                    }
                }
                if (attend.getType().equals("3")) {
                    attenda.setTime(atime1);
                    if (attend.getAtime() == null) {
                        state = "未签到";
                    } else {
                        if ((this.reTime(attend.getAtime()).intValue()) < (DateFormat.getWYQTime(attendSets.getAtime3()))) {
                            state = "正常";
                        } else if ((this.reTime(attend.getAtime()).intValue()) > (DateFormat.getWYQTime(attendSets.getAtime3()))) {
                            state = "迟到";
                        }
                    }
                }
                if (attend.getType().equals("4")) {
                    attenda.setTime(atime1);
                    if (attend.getAtime() == null) {
                        state = "未签退";
                    } else {
                        if ((this.reTime(attend.getAtime()).intValue()) > (DateFormat.getWYQTime(attendSets.getAtime4()))) {
                            state = "正常";
                        } else if ((this.reTime(attend.getAtime()).intValue()) < (DateFormat.getWYQTime(attendSets.getAtime4()))) {
                            state = "早退";
                        }
                    }
                }
                if (attend.getType().equals("5")) {
                    if (attend.getAtime() == null) {
                        state = "未签到";
                    } else {
                        if (attendSets.getAtime5Set() != null) {
                            attenda.setTime(atime1);
                            if ((this.reTime(attend.getAtime()).intValue()) < (DateFormat.getWYQTime(attendSets.getAtime5()))) {
                                state = "正常";
                            } else if ((this.reTime(attend.getAtime()).intValue()) > (DateFormat.getWYQTime(attendSets.getAtime5()))) {
                                state = "迟到";
                            }
                        } else {
                            continue;
                        }

                    }
                }
                if (attend.getType().equals("6")) {
                    if (attend.getAtime() == null) {
                        state = "未签退";
                    } else {
                        if (attendSets.getAtime6Set() != null) {
                            attenda.setTime(atime1);
                            if ((this.reTime(attend.getAtime()).intValue()) > (DateFormat.getWYQTime(attendSets.getAtime6()))) {
                                state = "正常";
                            } else if ((this.reTime(attend.getAtime()).intValue()) < (DateFormat.getWYQTime(attendSets.getAtime6()))) {
                                state = "早退";
                            }
                        } else {
                            continue;
                        }
                    }
                }

                attenda.setDateStr(date);
                attenda.setAtimestate(state);

                attendb.add(attenda);
            }

            if (list != null) {
                json.setFlag(0);
                json.setMsg("查询成功");
//            json.setObject(listDate);
                json.setObj(attendb);
            } else {
                json.setFlag(1);
                json.setMsg("查询失败");
            }
        } catch (Exception e) {
            json.setFlag(1);
            json.setMsg("查询失败");
        }

        return json;
    }

    public static long getTimeDifference(Date date1, Date date2) {
        //一天的毫秒数
        long d = 1000 * 24 * 60 * 60;
//一小时的毫秒数
        long h = 1000 * 60 * 60;
//一分钟的毫秒数
        long m = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long timeDiff = date2.getTime() - date1.getTime();
        // 计算差多少天
        long day = timeDiff / d;
        // 计算差多少小时
        long hour = timeDiff % d / h;
        // 计算差多少分钟
        long min = timeDiff % d % h / m;
        //输出结果
        return hour;
    }

    public final String userPriv1 = "OA管理员";

    public ToJson queryAttendDept(HttpServletRequest request) {
        ToJson<Department> json = new ToJson<>();
        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionId);
        json.setFlag(1);
        json.setMsg("没有数据");
        if (user != null) {
            List<Department> departmentList = new ArrayList<Department>();
            if (userPriv1.equals(user.getUserPrivName())) {
                departmentList = departmentMapper.getDatagrid();
            } else {
                Department department = departmentMapper.getDeptById(user.getDeptId());
                departmentList.add(department);
            }
            if (departmentList != null && departmentList.size() > 0) {
                json.setFlag(0);
                json.setMsg("查询成功");
                json.setObject(departmentList);
            } else {
                json.setFlag(1);
                json.setMsg("没有数据");
            }
        }
        return json;
    }

    public Long reTime(Integer time) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        String re_StrTime = null;
        Long lcc_time = null;
        if (time.toString().length() == 13) {
            lcc_time = Long.valueOf(time);
        } else {
            lcc_time = Long.valueOf(time * 1000L);
        }
        re_StrTime = sdf.format(lcc_time);
        Date dateStart = sdf.parse(re_StrTime);
        long res = dateStart.getTime();
        return res;
    }


    public ToJson queryAttendUsers(HttpServletRequest request) {
        ToJson<Department> json = new ToJson<>();
        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionId);
        json.setFlag(1);
        json.setMsg("没有数据");
        if (user != null) {
            List<Users> users = new ArrayList<Users>();
            if (userPriv1.equals(user.getUserPrivName())) {
                users = usersMapper.selectAllUsers();
                json.setFlag(0);
                json.setMsg("查询成功");
                json.setObject(users);
                return json;
            }
            Department department = departmentMapper.getDeptById(user.getDeptId());
            if (user.getUserId().equals(department.getManager())) {
                users = usersMapper.getUsersByDeptId(user.getDeptId());
            } else {
                Users use = usersMapper.getUsersByuserId(user.getUserId());
                users.add(use);
            }
            if (users != null && users.size() > 0) {
                json.setFlag(0);
                json.setMsg("查询成功");
                json.setObject(users);
            } else {
                json.setFlag(1);
                json.setMsg("没有数据");
            }
        }
        return json;
    }

    public BaseWrapper importAttend(MultipartFile file, HttpServletRequest request) {
        BaseWrapper baseWrapper = new BaseWrapper();
        try {
            //判读当前系统
            //读取配置文件
            ResourceBundle rb = ResourceBundle.getBundle("upload");
            String osName = System.getProperty("os.name");
            StringBuffer path = new StringBuffer();
            StringBuffer buffer = new StringBuffer();
            if (osName.toLowerCase().startsWith("win")) {
                //sb=sb.append(rb.getString("upload.win"));
                //判断路径是否是相对路径，如果是的话，加上运行的路径
                String uploadPath = rb.getString("upload.win");
                if (uploadPath.indexOf(":") == -1) {
                    //获取运行时的路径
                    String basePath = this.getClass().getClassLoader().getResource(".").getPath() + File.pathSeparator;
                    //获取截取后的路径
                    String str2 = "";
                    if (basePath.indexOf("/xoa") != -1) {
                        //获取字符串的长度
                        int length = basePath.length();
                        //返回指定字符在此字符串中第一次出现处的索引
                        int index = basePath.indexOf("/xoa");
                        //从指定位置开始到指定位置结束截取字符串
                        str2 = basePath.substring(0, index);
                    }
                    path = path.append(str2 + "/xoa");
                }
                path.append(uploadPath);
                buffer = buffer.append(rb.getString("upload.win"));
            } else {
                path = path.append(rb.getString("upload.linux"));
                buffer = buffer.append(rb.getString("upload.linux"));
            }
            // 判断是否为空文件
            if (file.isEmpty()) {
                baseWrapper.setMsg("请上传文件");
                return baseWrapper;
            } else {
                String fileName = file.getOriginalFilename();
                if (fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) {
                    String uuid = UUID.randomUUID().toString().replaceAll("-", "");
                    int pos = fileName.indexOf(".");
                    String extName = fileName.substring(pos);
                    String newFileName = uuid + extName;
                    File dest = new File(path.toString(), newFileName);
                    file.transferTo(dest);
                    // 将文件上传成功后进行读取文件
                    // 进行读取的路径
                    String readPath = path.append(System.getProperty("file.separator")).append(newFileName).toString();
                    InputStream in = new FileInputStream(readPath);
                    HSSFWorkbook excelObj = new HSSFWorkbook(in);
                    HSSFSheet sheetObj = excelObj.getSheetAt(0);
                    Row row = sheetObj.getRow(0);
                    int colNum = row.getPhysicalNumberOfCells();
                    int lastRowNum = sheetObj.getLastRowNum();
                    Attend attend = null;
                    for (int i = 3; i <= lastRowNum; i++) {
                        attend = new Attend();
                        row = sheetObj.getRow(i);
                        if (null != row) {
                            for (int j = 0; j < colNum; j++) {
                                Cell cell = row.getCell(j);
                                String cellValue = null;
                                if (null == cell) {
                                    continue;
                                } else {
                                    cellValue = cell.getStringCellValue();
                                }
                                if (null != cellValue) {
                                    switch (j) {
                                        case 0:
                                            //姓名
                                            Users users = usersMapper.getUserByUserName(cellValue);
                                            if (null != users && null != users.getUserId()) {
                                                attend.setUid(Integer.parseInt(users.getUserId()));
                                            }
                                            break;
                                        case 1:
                                            //登记日期
                                            attend.setDate(DateFormat.DateToStr(cellValue));
                                            break;
                                        case 2:
                                            //签到次数
                                            attend.setType(cellValue);
                                            break;
                                        case 3:
                                            //签到时间
                                            attend.setAtime(DateFormat.getTime(cellValue));
                                            break;
                                        case 4:
                                            //定位地点名称
                                            attend.setAddress(cellValue);
                                            break;
                                        case 5:
                                            //备注
                                            attend.setRemark(cellValue);
                                            break;
                                        case 6:
                                            //签到手机ID号
                                            attend.setRemark(cellValue);
                                            break;
                                        case 7:
                                            //设备型号
                                            attend.setRemark(cellValue);
                                            break;
                                    }
                                }
                            }
                            if (null != attend.getUid()) {
                                //此sql要求传主键。。。。。。
                                attend.setAid(0);
                                attendMapper.addAttend(attend);
                            }
                        }
                    }
                }
            }
            baseWrapper.setStatus(true);
            baseWrapper.setFlag(true);
            baseWrapper.setCode("200");
        } catch (Exception e) {
            e.printStackTrace();
            baseWrapper.setMsg("出现异常");
            baseWrapper.setStatus(false);
            baseWrapper.setFlag(false);
        }
        return baseWrapper;
    }

    public List<AttendWrappers> attendUnitException(String start, String end, Integer uid, HttpServletRequest request) {
        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users users = SessionUtils.getSessionInfo(request.getSession(),
                Users.class, new Users(), redisSessionId);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("strat", start);
        map.put("end", end);
        map.put("uid", uid);
        List<Attend> attendList = attendMapper.queryCountPhone(map);
        List<Integer> attendList1 = new ArrayList<Integer>();
        List<Attend> attendList3 = new ArrayList<Attend>();
        List<AttendWrappers> unitExceptionList = new ArrayList<AttendWrappers>();

        Attend attendNew = new Attend();
        for (Attend attend1 : attendList) {
            attendList1.add(attend1.getCount());
            Integer a1 = attend1.getCount();
        }
        if (attendList1 != null && attendList1.size() > 0) {
            Integer integer = Collections.max(attendList1);
            int i = integer.intValue();
            double b = i * 0.3;
            for (Attend attend1 : attendList) {
                if (b < attend1.getCount()) {

                } else {

                    String phone = attend1.getPhoneId();
                    Map<String, Object> maps = new HashMap<String, Object>();
                    maps.put("phone", phone);
                    maps.put("strat", start);
                    maps.put("end", end);
                    List<Attend> attendList2 = attendMapper.queryAttendPhone(maps);
                    for (Attend attend11 : attendList2) {
                        com.xoa.service.attend.wrapper.UnitException unitException = new com.xoa.service.attend.wrapper.UnitException();
                        unitException.setDate(DateFormat.getDatestrTime(attend11.getDate()));
                        unitException.setTime(DateFormat.getwyqStrTime(attend11.getAtime()));
                        unitException.setPhoneId(attend11.getPhoneId());
                        unitException.setAtime(DateFormat.getDatestrTime(attend11.getDate()) + "    " + DateFormat.getwyqStrTime(attend11.getAtime()));
                        Map<String, Object> map1 = new HashMap<String, Object>();
                        String msg = "";
                        if (!users.getUid().equals(attend11.getUid())) {
                            String name = usersMapper.getUsernameById(attend11.getUid());
                            msg = "疑似" + name + "代签";
                        } else {
                            msg = "新设备" + phone;
                        }
                        unitException.setStr(msg);
                        unitExceptionList.add(unitException);

                    }
                }
            }
        }
        return unitExceptionList;
    }


    private AttendWrappers attSet(Date nowdate, AttendSet attendSet, int i) throws Exception {
        AttendWrappers attendWrappers = new AttendWrappers();
        attendWrappers.setDate(DateFormat.getDatestr(nowdate));//具体日期
        switch (i) {
            case 1:
                attendWrappers.setTime(attendSet.getAtime1());//应签到时间
                break;
            case 2:
                attendWrappers.setTime(attendSet.getAtime2());//应签到时间
                break;
            case 3:
                attendWrappers.setTime(attendSet.getAtime3());//应签到时间
                break;
            case 4:
                attendWrappers.setTime(attendSet.getAtime4());//应签到时间
                break;
            case 5:
                attendWrappers.setTime(attendSet.getAtime5());//应签到时间
                break;
            case 6:
                attendWrappers.setTime(attendSet.getAtime6());//应签到时间
                break;
        }
        return attendWrappers;
    }


    /**
     * 获取应签到次数
     */
    public Map<String, List<String>> getQianDaoCiShu(AttendSet attendSet) {
        Map<String, List<String>> map = new HashMap<>();
        List<String> yingqiandao = new ArrayList<>();
        List<String> yingqiantui = new ArrayList<>();
        if (attendSet != null) {
            if (attendSet.getAtime1Setother().equals("1")) {
                if (attendSet.getCommute1().equals("1")) {
                    yingqiandao.add("1");
                } else {
                    yingqiantui.add("1");
                }
            }
            if (attendSet.getAtime2Setother().equals("1")) {
                if (attendSet.getCommute2().equals("1")) {
                    yingqiandao.add("2");
                } else {
                    yingqiantui.add("2");
                }
            }
            if (attendSet.getAtime3Setother().equals("1")) {
                if (attendSet.getCommute3().equals("1")) {
                    yingqiandao.add("3");
                } else {
                    yingqiantui.add("3");
                }
            }
            if (attendSet.getAtime4Setother().equals("1")) {
                if (attendSet.getCommute4().equals("1")) {
                    yingqiandao.add("4");
                } else {
                    yingqiantui.add("4");
                }
            }
            if (attendSet.getAtime5Setother().equals("1")) {
                if (attendSet.getCommute5().equals("1")) {
                    yingqiandao.add("5");
                } else {
                    yingqiantui.add("5");
                }
            }
            if (attendSet.getAtime6Setother().equals("1")) {
                if (attendSet.getCommute6().equals("1")) {
                    yingqiandao.add("6");
                } else {
                    yingqiantui.add("6");
                }
            }
        }
        map.put("yingqiandao", yingqiandao);
        map.put("yingqiantui", yingqiantui);
        return map;
    }

    /**
     * 返回分好组的userDutyList
     *
     * @return
     */
    public List<Object> getUserDutyList(Map<String, Object> map) {
        //获取符合查询条件的记录
        List<Integer> uids = userDutyMapper.getUserDutyListByMap(map);
        if (uids != null && uids.size() > 0) {
            List<UserDuty> userDutyList = userDutyMapper.getUserDutyListByUidList(uids, map);
            Set<Integer> uidSet = new HashSet<>(uids);
            /*if (userDutyList != null && userDutyList.size() > 0) {
                for (int i = 0; i < userDutyList.size(); i++) {
                    uidSet.add(userDutyList.get(i).getUid());
                }
            }*/
            //定义分组后的list
            List<Object> userDutys = new ArrayList<>();
            //去重完毕
            List<Integer> uidList = new ArrayList<>(uidSet);
            if (uidList != null && uidList.size() > 0) {
                //按照uid进行分组list
                for (int i = 0; i < uidList.size(); i++) {
                    Integer uid = uidList.get(i);
                    List userDuties = new ArrayList<>();
                    for (int j = 0; j < userDutyList.size(); j++) {
                        Integer uid2 = userDutyList.get(j).getUid();
                        if (uid2.equals(uid)) {
                            userDuties.add(userDutyList.get(j));
                        }
                    }
                    //装配分组后的list
                    if (userDuties != null && userDuties.size() > 0) {
                        paixuUserDuty(userDuties);
                        userDutys.add(userDuties);
                    } else {
                        userDutys.add(uid);
                    }
                }
            }
            return userDutys;
        }

        return null;
    }

    private void paixuUserDuty(List<UserDuty> list) {
        Collections.sort(list, new Comparator<UserDuty>() {
            @Override
            public int compare(UserDuty o1, UserDuty o2) {
                try {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    int flag = sdf.parse(o1.getDutyDate()).compareTo(sdf.parse(o2.getDutyDate()));
                    return flag;
                } catch (Exception e) {
                    System.out.println(e);
                }
                return 0;
            }
        });
    }

    /**
     * lr
     * 获取每月有多少天
     *
     * @param date
     * @return
     */
    public Integer getMonthMaxDay(String date) {
        Calendar cal = Calendar.getInstance();
        /**设置date**/
        // String date="2018-02";
        SimpleDateFormat oSdf = new SimpleDateFormat("", Locale.ENGLISH);
        oSdf.applyPattern("yyyy-MM");
        try {
            oSdf.parse(date);
            cal.setTime(oSdf.parse(date));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int num2 = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        return num2;
    }

    //lr 获取应出勤天数
    public List getDutyDays(String beiginDate, String endDate) {
        //用于格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<String> yingchuqinDate = new ArrayList<>();
        Date startTime = null;
        Date endTime = null;
        try {
            startTime = sdf.parse(beiginDate);
            endTime = sdf.parse(endDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        double leaveDays = 0;
        //从startTime开始循环，若该日期不是节假日或者不是周六日则请假天数+1
        Date flag = startTime;//设置循环开始日期
        Calendar cal = Calendar.getInstance();
        //从数据库得到节假日的起始日期和终止日期
        List<AttendHoliday> holidays = holidayMapper.selHolidayByMonth(beiginDate, endDate);
        int week;
        outer:
        while (flag.compareTo(endTime) != 1) {
            cal.setTime(flag);
            //判断是否为周六日
            week = cal.get(Calendar.DAY_OF_WEEK) - 1;
            if (week == 0 || week == 6) {//0为周日，6为周六
                //跳出循环进入下一个日期
                cal.add(Calendar.DAY_OF_MONTH, +1);
                flag = cal.getTime();
                continue;
            } else {
                //判断是否为节假日
                if (holidays != null || !holidays.isEmpty()) {
                    inner:
                    for (AttendHoliday holiday : holidays) {
                        if (flag.compareTo((Date) holiday.getBeginDate()) > -1 && flag.compareTo((Date) holiday.getEndDate()) < 1) {
                            //跳出循环进入下一个日期
                            cal.add(Calendar.DAY_OF_MONTH, +1);
                            flag = cal.getTime();
                            continue outer;
                        }
                    }
                }
            }
            leaveDays = leaveDays + 1;
            //日期往后加一天
            cal.add(Calendar.DAY_OF_MONTH, +1);
            String date = sdf.format(flag);
            yingchuqinDate.add(date);
            flag = cal.getTime();
        }
        return yingchuqinDate;
    }


    public AttendSetWrappers findAttendList(String dutyType, Integer deptId,
                                            String beiginDate, String endDate, Integer pageNo, Integer pageSize, HttpServletRequest req) throws Exception {
        AttendSetWrappers wrappers = new AttendSetWrappers();
        if (endDate == null) {
            endDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        }
        if (beiginDate == null) {
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DATE, -7);
            beiginDate = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());

        }
        //查出user中部门id为deptid的所有人(姓名，部门)
        Map<String, Object> useMap = new HashMap<>();
        useMap.put("deptId", deptId);
        pageNo = pageNo - 1;
        if (pageNo != 0) {
            pageNo = pageNo * pageSize;
        }
        useMap.put("pageNo", pageNo);
        useMap.put("pageSize", pageSize);
        List<Users> usersList = usersMapper.getUsersByDeptIdAndPage(useMap);

        Iterator<Users> usersIterator = usersList.iterator();
        Date dateTime = new Date();
        SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
        String time = format.format(dateTime);
        Date dateTime1 = new Date();
        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        String time1 = format1.format(dateTime1);

        int days = 0;
        //查询免签节假日信息表attend_holiday中节日开始时间大于startTime小于endTime之后的节假日
        List<AttendHoliday> holidays = holidayMapper.selHolidayByMonth(beiginDate, endDate);
        List<String> holidayList = new ArrayList<>();
        List<Date> yingChuQin = null;
        List<String> betweenDates = null;


        //List<AttendBase> attendStatisticAll=attendStatisticAll=new ArrayList<>();
        List<AttendBase> attendStatisticAll = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        while (usersIterator.hasNext()) {
            List<Date> date = new ArrayList<Date>();
            Users users = usersIterator.next();

            Integer uid = users.getUid();
            //根据用户id   查询用户扩展信息
            String deptName = users.getDeptName();
            UserExt userExt = userExtMapper.queryUserExt(users.getUid());
            if (userExt != null) {
                Long timeDifference = (long) 0; //加班时长统计
                int dutyCount = 0; //值班天数统计
                List<AttendWrappers> normal = new ArrayList<AttendWrappers>();//上班正常
                List<AttendWrappers> normalyichang = new ArrayList<AttendWrappers>();//设备异常
                List<AttendWrappers> closed = new ArrayList<AttendWrappers>();//下班正常
                List<AttendWrappers> notSign = new ArrayList<AttendWrappers>();//未签到
                List<AttendWrappers> notOut = new ArrayList<AttendWrappers>();//未签退
                List<AttendWrappers> leaveEarly = new ArrayList<AttendWrappers>();//早退
                List<AttendWrappers> late = new ArrayList<AttendWrappers>();//迟到
                List<AttendWrappers> fields = new ArrayList<AttendWrappers>();//外勤
                List<AttendWrappers> attendance = new ArrayList<AttendWrappers>();//加班
                List<AttendWrappers> evection = new ArrayList<AttendWrappers>();//出差
                List<AttendWrappers> leave = new ArrayList<AttendWrappers>();//请假
                List<AttendWrappers> out = new ArrayList<AttendWrappers>();//外出
                List<AttendWrappers> overTime = new ArrayList<AttendWrappers>();//加班时长
                List<AttendWrappers> duty = new ArrayList<AttendWrappers>();//值班时长

                AttendSet attendSet = null;
                UserDuty userDuty = userDutyMapper.userDuty(uid, time1);
                if (userDuty != null) {
                    attendSet = attendSetMapper.selectAttendSetSid(userDuty.getDutyType());
                }
                int xqhbt = 0;

                if (attendSet != null) {
                    String[] str1 = attendSet.getAtime1Set().split("\\|");
                    if (numberOne.equals(str1[0])) {
                        xqhbt++;
                    }
                    //第一次签到开关
                    attendSet.setAtime1Setother(str1[0]);
                    //第一次上下班开关
                    attendSet.setCommute1(str1[1]);
                    String[] str2 = attendSet.getAtime2Set().split("\\|");
                    if (numberOne.equals(str2[0])) {
                        xqhbt++;
                    }

                    attendSet.setAtime2Setother(str2[0]);
                    attendSet.setCommute2(str2[1]);
                    String[] str3 = attendSet.getAtime3Set().split("\\|");
                    if (numberOne.equals(str3[0])) {
                        xqhbt++;
                    }

                    attendSet.setAtime3Setother(str3[0]);
                    attendSet.setCommute3(str3[1]);
                    String[] str4 = attendSet.getAtime4Set().split("\\|");
                    if (numberOne.equals(str4[0])) {
                        xqhbt++;
                    }

                    attendSet.setAtime4Setother(str4[0]);
                    attendSet.setCommute4(str4[1]);
                    String[] str5 = attendSet.getAtime5Set().split("\\|");
                    if (numberOne.equals(str5[0])) {
                        xqhbt++;
                    }

                    attendSet.setAtime5Setother(str5[0]);
                    attendSet.setCommute5(str5[1]);
                    String[] str6 = attendSet.getAtime6Set().split("\\|");
                    if (numberOne.equals(str6[0])) {
                        xqhbt++;
                    }
                    attendSet.setAtime6Setother(str6[0]);
                    attendSet.setCommute6(str6[1]);

                    Calendar c = Calendar.getInstance();
                    List<Date> dates = DateCompute.getBetweenDates(DateFormat.DateToStr(beiginDate), DateFormat.DateToStr(endDate));
                    for (Date nowdate1 : dates) {
                        c.setTime(nowdate1);
                        int weekInt = c.get(Calendar.DAY_OF_WEEK);
                        weekInt = weekInt - 1;
                        if (weekInt == 0) {
                            weekInt = 7;
                        }

                        String week = String.valueOf(weekInt);
                        if (attendSet.getWorkdate().contains(week)) {
                            date.add(nowdate1);
                        }
                    }
                    normalyichang = attendUnitException(beiginDate, endDate, uid, req);

                    try {
                        for (AttendHoliday attendHoliday : holidays) {
                            betweenDates = AttendUtil.getMonthBetweenDateStr(DateFormat.getDatestr(attendHoliday.getBeginDate()), DateFormat.getDatestr(attendHoliday.getEndDate()), null);
                            holidayList.addAll(betweenDates);
                        }
                    } catch (ParseException pe) {

                    }
                    //获取当月天数减去当月节假日(应出勤天数)
                    yingChuQin = AttendUtil.removeDuplicate(holidayList, date);
                    for (Date nowdate : yingChuQin) {
                        if (numberOne.equals(attendSet.getIsOut())) {
                            List<Attend> attend0 = attendMapper.selectAttend0(DateFormat.getDatestr(nowdate), uid);
                            if (attend0 != null && attend0.size() > 0) {
                                Iterator<Attend> attendIterator = attend0.iterator();
                                while (attendIterator.hasNext()) {
                                    FieldWorkWrappers field = new FieldWorkWrappers();//外勤
                                    Attend attend1 = attendIterator.next();
                                    field.setDate(DateFormat.getDatestrTime(nowdate));
                                    field.setTime(DateFormat.getwyqStrTime(attend1.getAtime()));
                                    field.setStr(attend1.getAddress());
                                    field.setPhoneId(attend1.getPhoneId());
                                    field.setCause(attend1.getRemark());
                                    fields.add(field);
                                }
                            }

                        }

                        if (numberOne.equals(attendSet.getIsDuty())) {
                            Attend attendcount = attendMapper.getAttendDetailByType(String.valueOf(users.getUid()), "9", DateFormat.getDatestr(nowdate));
                            if (attendcount != null) {
                                dutyCount++;
                            }
                        }
                        if (numberOne.equals(attendSet.getIsOvertime())) { //加班
                            Attend begin = attendMapper.getAttendDetailByType(String.valueOf(users.getUid()), "7", DateFormat.getDatestr(nowdate));
                            Attend end = attendMapper.getAttendDetailByType(String.valueOf(users.getUid()), "8", DateFormat.getDatestr(nowdate));
                            if (begin != null && end != null) {
                                Integer startTime = begin.getAtime();
                                String beginDate = new SimpleDateFormat("yyyy-MM-dd").format(begin.getDate()) + " " + new SimpleDateFormat(" HH:mm:ss").format(Long.valueOf(startTime));
                                Integer enddate = end.getAtime();
                                String jieshu = new SimpleDateFormat("yyyy-MM-dd").format(end.getDate()) + " " + new SimpleDateFormat(" HH:mm:ss").format(Long.valueOf(enddate));
                                try {
                                    timeDifference += getTimeDifference(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(beginDate), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(jieshu));
                                } catch (ParseException e) {
                                    e.printStackTrace();
                                }
                            }

                        }

                        if (numberOne.equals(attendSet.getAtime1Setother())) {
                            if (DateFormat.getDateTimes(attendSet.getAtime1()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                                if (numberOne.equals(attendSet.getCommute1())) {
                                    Attend attend1 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberOne);
                                    if (attend1 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend1.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime1()).getTime()) {
                                            //迟到
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 1);
                                            //迟到时间
                                            attendWrappers.setDateAll(DateFormat.parseMillisecone(reTime(attend1.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime1())));
                                            late.add(attendWrappers);
                                        } else {
                                            //正常上班
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 1);
                                            //上班签到时间
                                            attendWrappers.setDateAll(sdf.format(reTime(attend1.getAtime())));
                                            normal.add(attendWrappers);
                                        }
                                    } else {
                                        //未签到
                                        AttendWrappers attendWrappers = attSet(nowdate, attendSet, 1);
                                        notSign.add(attendWrappers);
                                    }

                                } else {
                                    Attend attend1 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberOne);
                                    if (attend1 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend1.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime1()).getTime()) {
                                            //早退
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 1);
                                            //早退时间
                                            attendWrappers.setDateAll(DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime1()) - reTime(attend1.getAtime())));
                                            leaveEarly.add(attendWrappers);
                                        } else {
                                            //正常下班
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 1);
                                            //下班签到时间
                                            attendWrappers.setDateAll(sdf.format(reTime(attend1.getAtime())));
                                            closed.add(attendWrappers);
                                        }
                                    } else {
                                        //未签退
                                        AttendWrappers attendWrappers = attSet(nowdate, attendSet, 1);
                                        notOut.add(attendWrappers);
                                    }


                                }
                            }
                        }
                        if (numberOne.equals(attendSet.getAtime2Setother())) {
                            if (DateFormat.getDateTimes(attendSet.getAtime2()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                                if (numberOne.equals(attendSet.getCommute2())) {
                                    Attend attend2 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberTwo);
                                    if (attend2 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend2.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime2()).getTime()) {
                                            //迟到
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 2);
                                            //迟到时间
                                            attendWrappers.setDateAll(DateFormat.parseMillisecone(reTime(attend2.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime2())));
                                            late.add(attendWrappers);
                                        } else {
                                            //正常上班
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 2);
                                            //上班签到时间
                                            attendWrappers.setDateAll(sdf.format(reTime(attend2.getAtime())));
                                            normal.add(attendWrappers);
                                        }
                                    } else {
                                        //未签到
                                        AttendWrappers attendWrappers = attSet(nowdate, attendSet, 2);
                                        notSign.add(attendWrappers);
                                    }

                                } else {
                                    Attend attend2 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberTwo);
                                    if (attend2 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend2.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime2()).getTime()) {
                                            //早退
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 2);
                                            //早退时间
                                            attendWrappers.setDateAll(DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime2()) - reTime(attend2.getAtime())));
                                            leaveEarly.add(attendWrappers);
                                        } else {
                                            //正常下班
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 2);
                                            //下班签到时间
                                            attendWrappers.setDateAll(sdf.format(reTime(attend2.getAtime())));
                                            closed.add(attendWrappers);
                                        }
                                    } else {
                                        //未签退
                                        AttendWrappers attendWrappers = attSet(nowdate, attendSet, 2);
                                        notOut.add(attendWrappers);
                                    }


                                }
                            }
                        }
                        if (numberOne.equals(attendSet.getAtime3Setother())) {
                            if (DateFormat.getDateTimes(attendSet.getAtime3()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                                if (numberOne.equals(attendSet.getCommute3())) {
                                    Attend attend3 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberThree);
                                    if (attend3 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend3.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime3()).getTime()) {
                                            //迟到
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 3);
                                            //迟到时间
                                            attendWrappers.setDateAll(DateFormat.parseMillisecone(reTime(attend3.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime3())));
                                            late.add(attendWrappers);
                                        } else {
                                            //正常上班
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 3);
                                            //上班签到时间
                                            attendWrappers.setDateAll(sdf.format(reTime(attend3.getAtime())));
                                            normal.add(attendWrappers);
                                        }
                                    } else {
                                        //未签到
                                        AttendWrappers attendWrappers = attSet(nowdate, attendSet, 3);
                                        notSign.add(attendWrappers);
                                    }

                                } else {
                                    Attend attend3 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberThree);
                                    if (attend3 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend3.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime3()).getTime()) {
                                            //早退
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 3);
                                            //早退时间
                                            attendWrappers.setDateAll(DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime3()) - reTime(attend3.getAtime())));
                                            leaveEarly.add(attendWrappers);
                                        } else {
                                            //正常下班
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 3);
                                            //下班签到时间
                                            attendWrappers.setDateAll(sdf.format(reTime(attend3.getAtime())));
                                            closed.add(attendWrappers);
                                        }
                                    } else {
                                        //未签退
                                        AttendWrappers attendWrappers = attSet(nowdate, attendSet, 3);
                                        notOut.add(attendWrappers);
                                    }


                                }
                            }
                        }
                        if (numberOne.equals(attendSet.getAtime4Setother())) {
                            if (DateFormat.getDateTimes(attendSet.getAtime4()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                                if (numberOne.equals(attendSet.getCommute4())) {
                                    Attend attend4 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberFour);
                                    if (attend4 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend4.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime4()).getTime()) {
                                            //迟到
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 4);
                                            //迟到时间
                                            attendWrappers.setDateAll(DateFormat.parseMillisecone(reTime(attend4.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime4())));
                                            late.add(attendWrappers);
                                        } else {
                                            //正常上班
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 4);
                                            //上班签到时间
                                            attendWrappers.setDateAll(sdf.format(reTime(attend4.getAtime())));
                                            normal.add(attendWrappers);
                                        }
                                    } else {
                                        //未签到
                                        AttendWrappers attendWrappers = attSet(nowdate, attendSet, 4);
                                        notSign.add(attendWrappers);
                                    }

                                } else {
                                    Attend attend4 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberFour);
                                    if (attend4 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend4.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime4()).getTime()) {
                                            //早退
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 4);
                                            //早退时间
                                            attendWrappers.setDateAll(DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime4()) - reTime(attend4.getAtime())));
                                            leaveEarly.add(attendWrappers);
                                        } else {
                                            //正常下班
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 4);
                                            //下班签到时间
                                            attendWrappers.setDateAll(sdf.format(reTime(attend4.getAtime())));
                                            closed.add(attendWrappers);
                                        }
                                    } else {
                                        //未签退
                                        AttendWrappers attendWrappers = attSet(nowdate, attendSet, 4);
                                        notOut.add(attendWrappers);
                                    }


                                }
                            }
                        }
                        if (numberOne.equals(attendSet.getAtime5Setother())) {
                            if (DateFormat.getDateTimes(attendSet.getAtime5()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                                if (numberOne.equals(attendSet.getCommute5())) {
                                    Attend attend5 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberFive);
                                    if (attend5 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend5.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime5()).getTime()) {
                                            //迟到
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 5);
                                            //迟到时间
                                            attendWrappers.setDateAll(DateFormat.parseMillisecone(reTime(attend5.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime5())));
                                            late.add(attendWrappers);
                                        } else {
                                            //正常上班
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 5);
                                            //上班签到时间
                                            attendWrappers.setDateAll(sdf.format(reTime(attend5.getAtime())));
                                            normal.add(attendWrappers);
                                        }
                                    } else {
                                        //未签到
                                        AttendWrappers attendWrappers = attSet(nowdate, attendSet, 5);
                                        notSign.add(attendWrappers);
                                    }

                                } else {
                                    Attend attend5 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberFive);
                                    if (attend5 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend5.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime5()).getTime()) {
                                            //早退
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 5);
                                            //早退时间
                                            attendWrappers.setDateAll(DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime5()) - reTime(attend5.getAtime())));
                                            leaveEarly.add(attendWrappers);
                                        } else {
                                            //正常下班
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 5);
                                            //下班签到时间
                                            attendWrappers.setDateAll(sdf.format(reTime(attend5.getAtime())));
                                            closed.add(attendWrappers);
                                        }
                                    } else {
                                        //未签退
                                        AttendWrappers attendWrappers = attSet(nowdate, attendSet, 5);
                                        notOut.add(attendWrappers);
                                    }


                                }
                            }
                        }
                        if (numberOne.equals(attendSet.getAtime6Setother())) {

                            String status = "";
                            if (DateFormat.getDateTimes(attendSet.getAtime6()).getTime() < DateFormat.getDateTimes(time).getTime() || !date.equals(time1)) {

                                if (numberOne.equals(attendSet.getCommute6())) {
                                    Attend attend6 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberSix);
                                    if (attend6 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend6.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() > DateFormat.getDateTimes(attendSet.getAtime6()).getTime()) {
                                            //迟到
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 6);
                                            //迟到时间
                                            attendWrappers.setDateAll(DateFormat.parseMillisecone(reTime(attend6.getAtime()) - DateFormat.getWYQTime(attendSet.getAtime6())));
                                            late.add(attendWrappers);
                                        } else {
                                            //正常上班
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 6);
                                            //上班签到时间
                                            attendWrappers.setDateAll(sdf.format(reTime(attend6.getAtime())));
                                            normal.add(attendWrappers);
                                        }
                                    } else {
                                        //未签到
                                        AttendWrappers attendWrappers = attSet(nowdate, attendSet, 6);
                                        notSign.add(attendWrappers);
                                    }

                                } else {
                                    Attend attend6 = attendMapper.selectAttendAll(DateFormat.getDatestr(nowdate), uid, numberSix);
                                    if (attend6 != null) {

                                        String a1 = DateFormat.getwyqStrTime(attend6.getAtime());
                                        if (DateFormat.getDateTimes(a1).getTime() < DateFormat.getDateTimes(attendSet.getAtime6()).getTime()) {
                                            //早退
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 6);
                                            //早退时间
                                            attendWrappers.setDateAll(DateFormat.parseMillisecone(DateFormat.getWYQTime(attendSet.getAtime6()) - reTime(attend6.getAtime())));
                                            leaveEarly.add(attendWrappers);
                                        } else {
                                            //正常下班
                                            AttendWrappers attendWrappers = attSet(nowdate, attendSet, 6);
                                            //下班签到时间
                                            attendWrappers.setDateAll(sdf.format(reTime(attend6.getAtime())));
                                            closed.add(attendWrappers);
                                        }
                                    } else {
                                        //未签退
                                        AttendWrappers attendWrappers = attSet(nowdate, attendSet, 6);
                                        notOut.add(attendWrappers);
                                    }


                                }
                            }
                        }
                    }
                }
                AttendBase attendBase = new AttendBase();

                attendBase.setUserName(users.getUserName());

                attendBase.setDeptName(users.getDeptName());

                attendBase.setUid(users.getUid());

                attendBase.setYingChuQin(yingChuQin.size());//应出勤
                attendBase.setYingChuQinList(yingChuQin);

                attendBase.setShangBanZhengChang(normal.size());
                attendBase.setShangBanZhengChangList(normal);//上班正常

                attendBase.setXiaBanZhengChang(closed.size());
                attendBase.setXiaBanZhengChangList(closed);//下班正常

                attendBase.setWeiQianDao(notSign.size());
                attendBase.setWeiQianDaoList(notSign);//未签到

                attendBase.setWeiQianTui(notOut.size());
                attendBase.setWeiQianTuiList(notOut);//未签退

                attendBase.setChiDao(late.size());
                attendBase.setChiDaoList(late);//迟到

                attendBase.setZaoTui(leaveEarly.size());
                attendBase.setZaoTuiList(leaveEarly);//早退

                attendBase.setSheBeiYiChang(normalyichang.size());
                attendBase.setSheBeiYiChangList(normalyichang);//異常

                attendBase.setWaiQin(fields.size());
                attendBase.setWaiQinList(fields);//外勤

                attendBase.setJiaBan(Integer.parseInt(String.valueOf(timeDifference)));
                attendBase.setJiaBanList(attendance);//加班

                attendBase.setZhiBan(dutyCount); //值班天数
                attendBase.setChuChaiList(evection);//出差

                attendBase.setQingJia(leave.size());
                attendBase.setQingJiaList(leave);//请假

                attendBase.setWaiChu(out.size());
                attendBase.setWaiChuList(out);//外出

                //实际出勤天数(一天内有一次正常签到或签退就算出勤)、
                List<AttendWrappers> shiJiChuqinAll = new ArrayList<AttendWrappers>();
                shiJiChuqinAll.addAll(normal);
                shiJiChuqinAll.addAll(closed);

                // 全勤（一天所有时间段签到和签退都为正常）、
                List<String> quanQin = new ArrayList<>();
                int falg = 0;
                for (Date strDate : yingChuQin) {
                    for (AttendWrappers AttendWrappers : shiJiChuqinAll) {
                        if (AttendWrappers.getDate().equals(strDate)) {
                            falg++;
                            if (falg == xqhbt) {
                                quanQin.add(AttendWrappers.getDate());
                                falg = 0;
                            }
                        }
                    }
                }
                attendBase.setQuanQin(quanQin.size());
                attendBase.setQuanQinList(quanQin);


                List<AttendWrappers> shiJiChuqin = AttendUtil.removeDuplicate3(shiJiChuqinAll);
                attendBase.setShiJiChuqin(shiJiChuqin.size());
                attendBase.setShiJiChuqinList(shiJiChuqin);//实际出勤

                // 旷工天数（一天内没有一次签到记录或者签到）
                List<String> kuangGongAll = new CopyOnWriteArrayList<>();
                for (Date d : yingChuQin) {
                    kuangGongAll.add(DateFormat.getDatestr(d));
                }
                for (AttendWrappers b : shiJiChuqin) {
                    kuangGongAll.add(b.getDate());
                }

                List<String> kuangGong = AttendUtil.removeDuplicate2(kuangGongAll);

                attendBase.setKuangGong(kuangGong.size());
                attendBase.setKuangGongList(kuangGong);//旷工

                attendStatisticAll.add(attendBase);

            }
        }
        if (attendStatisticAll.size() > 0) {
            wrappers.setFlag(true);
            wrappers.setStatus(true);
            wrappers.setData(attendStatisticAll);
            wrappers.setMsg("查询成功");
        } else {
            wrappers.setFlag(false);
            wrappers.setStatus(true);
            wrappers.setMsg("查询失败");
        }
        return wrappers;
    }


    /**
     * 李然
     *
     * @param dutyType   考勤类型
     * @param deptId     部门id
     * @param beiginDate 起始时间
     * @param endDate    结束时间
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
   /* public AttendSetWrappers findAttendList2(Integer dutyType, Integer deptId,
                                             String beginDate,String endDate, Integer pageNo, Integer pageSize,Integer oneUid,
                                             HttpServletRequest req) {
        List<AttendBase> attendBaseList = new ArrayList<>();
        //用于格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //存储已经查到的attendset
        List<AttendSet> dutyTypeList = new ArrayList<>();
        //1、查询出符合条件的人员
        Map<String, Object> map = new HashMap<>();
        map.put("dutyType", dutyType);
        map.put("deptId", deptId);
        map.put("beginDate", beginDate);
        map.put("endDate", endDate);
        map.put("uid",oneUid);
        Integer total=userDutyMapper.getTotalByMap(map);
        Integer startNum=null;
        Integer endNum=null;
        if(pageNo!=null&&pageSize!=null){
            startNum=(pageNo-1)*pageSize;
            endNum=pageSize;
        }
        map.put("startNum",startNum);
        map.put("endNum",endNum);
        List<List<UserDuty>> userDutyList = getUserDutyList(map);//获得多个人员的排班
        if (userDutyList != null && userDutyList.size() > 0) { //遍历每一个人的排班
            for (int i = 0; i < userDutyList.size(); i++) {
                //是否需要查询attendSet表？
                boolean isAttendSet = true;
                //此uid用户的userDuty表，用这个数组查询考勤记录
                List<UserDuty> userDuties = userDutyList.get(i);
                Integer yingChuQin = 0;//应出勤天数
                Integer shangBanZhengChang = 0;//上班正常天数
                Integer xiaBanZhengChang = 0;//下班正常天数
                Integer weiQianDao = 0;//未签到天数
                Integer weiQianTui = 0;//未签退天数
                Integer chiDao = 0;//迟到天数
                Integer zaoTui = 0;//早退天数
                Integer sheBeiYiChang = 0;//異常
                Integer waiQin = 0;//外勤天数
                Double jiaBan = 0.0;//加班天数
                Integer zhiBan = 0;//值班天数
                Double qingJia = 0.0;//请假天数
                Double waiChu = 0.0;//外出天数
                Integer shiJiChuqin = 0;//实际出勤天数
                Integer kuangGong = 0;//旷工天数
                Integer quanQin = 0;//全勤天数
                Double chuChai = 0.0;//出差天数
                List<AttendWrappers> kuanggongList = new ArrayList<>();
                List<AttendWrappers> weiqiandaoList = new ArrayList<>();
                List<AttendWrappers> weiqiantuiList = new ArrayList<>();
                List<AttendWrappers> chidaoList = new ArrayList<>();
                List<AttendWrappers> zaotuiList = new ArrayList<>();
                List<AttendWrappers> yichangList = new ArrayList<>();
                List<AttendWrappers> qingjiaList = new ArrayList<>();
                List<AttendWrappers> waichuList = new ArrayList<>();
                List<AttendWrappers> jiabanList = new ArrayList<>();
                List<AttendWrappers> chuchaiList = new ArrayList<>();
                List<AttendWrappers> shangbanzhengchangList=new ArrayList<>();
                List<AttendWrappers> xiabanzhengchangList=new ArrayList<>();
                List<AttendWrappers> quanqinList=new ArrayList<>();
                List<BaseAttend> shebeiyichang=new ArrayList<>();
                List<Attend> waiqinList=new ArrayList<>();
                yingChuQin = userDuties.size();
                //当前list都是同一个uid，同一个dutyType
                Integer uid = userDuties.get(0).getUid();
                Integer dutytype = userDuties.get(0).getDutyType();
                //查询当前人员所在的部门是否有统计规则
                List<AttendRule> attendRuleList = attendRuleMapper.getAttendRuleByDept(deptId);
                AttendRule attendRule = null;
                //考虑全部部门情况
                if (attendRuleList != null && attendRuleList.size() >= 1) {
                    attendRule = attendRuleList.get(0);
                }
                //定义单次迟到早退多久算旷工
                Integer oneLateHour = null;
                Integer oneEarlyHour = null;
                //如果有统计规则
                if (attendRule != null) {
                    //单次迟到多久算矿工
                    oneLateHour = attendRule.getOneLateHour();
                    //单次早退多久算矿工
                    oneEarlyHour = attendRule.getOneEarlyHour();
                }
                //考勤设置表
                AttendSet attendSet = null;
                //查看是否查询过此考勤设置类型记录
                if (dutyTypeList != null && dutyTypeList.size() == 0) {
                    attendSet = attendSetMapper.queryAttendSetId(dutytype);
                    dutyTypeList.add(attendSet);
                }
                //如果有这个考勤表在不要再查询数据库
                for (AttendSet attendSet1 : dutyTypeList) {
                    if (attendSet1.getSid() == dutytype) {
                        attendSet = attendSet1;
                        isAttendSet = false;
                        break;
                    }
                }
                //当考勤id发生变化时再次查询新表
                if (isAttendSet == true) {
                    attendSet = attendSetMapper.queryAttendSetId(dutytype);
                }
                //此人的考勤记录（1天可能会有多个记录  上下班）
                List<Attend> attendList = attendMapper.getAttendListByUidAndDates(uid, userDuties);
                //定义Set去重时间
                Set<Date> attendDateSet = new HashSet<>();
                if (attendList != null && attendList.size() > 0) {
                    for (int a = 0; a < attendList.size(); a++) {
                        attendDateSet.add(attendList.get(a).getDate());
                    }
                }
                //定义每一个用户attend考勤，区分每一天（通过时间分组）
                List<List<Attend>> uidAttendList = new ArrayList<>();
                //去重后转为list
                List<Date> attendDateList = new ArrayList<>(attendDateSet);
                if (attendDateList != null && attendDateList.size() > 0) {
                    for (int b = 0; b < attendDateList.size(); b++) {
                        Date date1 = attendDateList.get(b);
                        List<Attend> attends = new ArrayList<>();
                        for (int c = 0; c < attendList.size(); c++) {
                            if (attendList.get(c).getDate().compareTo(date1) == 0) {
                                attends.add(attendList.get(c));
                            }
                        }
                        if (attends != null && attends.size() > 0) {
                            uidAttendList.add(attends);
                        }
                    }
                }
                //装配开关属性
                attendSet = setAttendSet(attendSet);
                String attendStr = attendSet.toString();
                //获取应签到次数
                Map<String, List<String>> daKa = getQianDaoCiShu(attendSet);
                List<String> yingqiandao=daKa.get("yingqiandao");
                List<String> yingqiantui=daKa.get("yingqiantui");
                int qiandaocishu = yingqiandao.size();
                int qiantuicishu = yingqiantui.size();
                //查找是否有没有签到的天数
                for (int e = 0; e < userDuties.size(); e++) {
                    String dutyDate = userDuties.get(e).getDutyDate();
                    boolean nokuanggong = false;
                    for (int f = 0; f < uidAttendList.size(); f++) {
                        if (sdf.format(uidAttendList.get(f).get(0).getDate()).equals(dutyDate)) {
                            nokuanggong = true;
                            break;
                        }
                    }
                    if (nokuanggong == false) {
                        kuangGong++;
                        //矿工
                        AttendWrappers kg = new AttendWrappers();
                        kg.setDate(dutyDate);
                        kg.setWeek(getWeekByData(dutyDate));
                        kg.setType("旷工");
                        weiQianDao = weiQianDao + qiandaocishu;
                        weiQianTui = weiQianTui + qiantuicishu;
                        //未签
                        Map<String,List<AttendWrappers>> weiQianMap=getWeiQian(attendSet,dutyDate);
                        //未签到
                        weiqiandaoList=weiQianMap.get("weiQianDao");
                        //未签退
                        weiqiantuiList=weiQianMap.get("weiQianTui");
                    }
                }
                //遍历这个用户的所有天数
                if (uidAttendList != null && uidAttendList.size() > 0) {
                    for (int d = 0; d < uidAttendList.size(); d++) {
                        //获得每一天的考勤
                        List<Attend> attends = uidAttendList.get(d);
                        boolean kuanggong = false;//是否矿工
                        int qiandaojishu = 0;
                        int qiantuijishu = 0;
                        //获取当天的所有签到类型
                        StringBuffer sb=new StringBuffer();
                        for (Attend attend : attends) {
                            //当前考勤记录 签到 时间
                            Integer atime = attend.getAtime();
                            String atimeStr = sdf.format(new Date(Long.valueOf(atime+"000")));
                            //当前签到次数
                            String type = attend.getType();
                            //装配签到次数，用来遍历是否有未签到未签退的
                            sb.append(type);
                            //设备异常（b）
                            shebeiyichang=myAttendUnitException(beginDate,endDate,uid,req);
                            switch (type) {
                                case "0":waiQin++;waiqinList.add(attend);break;
                                case "1":
                                    //如果开关开启中
                                    if (attendSet.getAtime1Setother().equals("1")) {
                                        if (attendSet.getAtime1() != null && !attendSet.getAtime1().equals("")) {
                                            //获得规定签到时间毫秒
                                            // Integer dateTime = DateFormat.getWYQTime(attendSet.getAtime1());
                                            Integer dateTime = null;
                                            String year = atimeStr +" "+attendSet.getAtime1();
                                            Date date1=null;
                                            try{
                                                date1 =sdf2.parse(year);
                                            }catch (Exception e){
                                                e.printStackTrace();
                                            }
                                            long l = date1.getTime();
                                            dateTime = (int)l;
                                            String str = String.valueOf(l);
                                            str = str.substring(0,str.length()-3);
                                            dateTime = Integer.parseInt(str);
                                            if (attendSet.getCommute1().equals("1")) {
                                                qiandaojishu++;
                                                //上班 :签到时间应小于等于dateTime规定签到时间（如果有统计规则，应增加矿工可能《签到时间>规定签到时间+迟到多久算旷工》）
                                                if (atime > dateTime) {
                                                    //迟到
                                                    chiDao++;
                                                    chidaoList.add(setAttendWrappers("迟到",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                } else {
                                                    //上班正常
                                                    shangBanZhengChang++;
                                                    shangbanzhengchangList.add(setAttendWrappers("上班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneLateHour != null) {
                                                    if (atime > (oneLateHour + dateTime)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                                //下班：签到时间应大于等于dateTime规定签到时间（如果有统计规则，应增加旷工可能《签到时间<规定时间-早退多久算旷工》）
                                            } else {
                                                qiantuijishu++;
                                                if (atime < dateTime) {
                                                    //早退
                                                    zaotuiList.add(setAttendWrappers("早退",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                    zaoTui++;
                                                } else {
                                                    //下班正常
                                                    xiaBanZhengChang++;
                                                    xiabanzhengchangList.add(setAttendWrappers("下班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneEarlyHour != null) {
                                                    if (atime < (dateTime - oneEarlyHour)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case "2"://如果开关开启中
                                    if (attendSet.getAtime2Setother().equals("1")) {
                                        if (attendSet.getAtime2() != null && !attendSet.getAtime2().equals("")) {
                                            //获得规定签到时间毫秒
                                            // Integer dateTime = DateFormat.getWYQTime(attendSet.getAtime2());
                                            Integer dateTime = null;
                                            String year = atimeStr +" "+attendSet.getAtime2();
                                            Date date1=null;
                                            try{
                                                date1 =sdf2.parse(year);
                                            }catch (Exception e){
                                                e.printStackTrace();
                                            }
                                            long l = date1.getTime();
                                            dateTime = (int)l;
                                            String str = String.valueOf(l);
                                            str = str.substring(0,str.length()-3);
                                            dateTime = Integer.parseInt(str);
                                            if (attendSet.getCommute2().equals("1")) {
                                                qiandaojishu++;
                                                //上班 :签到时间应小于等于dateTime规定签到时间（如果有统计规则，应增加矿工可能《签到时间>规定签到时间+迟到多久算旷工》）
                                                if (atime > dateTime) {
                                                    //迟到
                                                    chiDao++;
                                                    chidaoList.add(setAttendWrappers("迟到",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                } else {
                                                    //上班正常
                                                    shangBanZhengChang++;
                                                    shangbanzhengchangList.add(setAttendWrappers("上班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneLateHour != null) {
                                                    if (atime > (oneLateHour + dateTime)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                                //下班：签到时间应大于等于dateTime规定签到时间（如果有统计规则，应增加旷工可能《签到时间<规定时间-早退多久算旷工》）
                                            } else {
                                                qiantuijishu++;
                                                if (atime < dateTime) {
                                                    //早退
                                                    zaotuiList.add(setAttendWrappers("早退",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                    zaoTui++;
                                                } else {
                                                    //下班正常
                                                    xiaBanZhengChang++;
                                                    xiabanzhengchangList.add(setAttendWrappers("下班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneEarlyHour != null) {
                                                    if (atime < (dateTime - oneEarlyHour)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case "3"://如果开关开启中
                                    if (attendSet.getAtime3Setother().equals("1")) {
                                        if (attendSet.getAtime3() != null && !attendSet.getAtime3().equals("")) {
                                            //获得规定签到时间毫秒
                                            //  Integer dateTime = DateFormat.getWYQTime(attendSet.getAtime3());
                                            Integer dateTime = null;
                                            String year = atimeStr +" "+attendSet.getAtime3();
                                            Date date1=null;
                                            try{
                                                date1 =sdf2.parse(year);
                                            }catch (Exception e){
                                                e.printStackTrace();
                                            }
                                            long l = date1.getTime();
                                            dateTime = (int)l;
                                            String str = String.valueOf(l);
                                            str = str.substring(0,str.length()-3);
                                            dateTime = Integer.parseInt(str);
                                            if (attendSet.getCommute3().equals("1")) {
                                                qiandaojishu++;
                                                //上班 :签到时间应小于等于dateTime规定签到时间（如果有统计规则，应增加矿工可能《签到时间>规定签到时间+迟到多久算旷工》）
                                                if (atime > dateTime) {
                                                    //迟到
                                                    chiDao++;
                                                    chidaoList.add(setAttendWrappers("迟到",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                } else {
                                                    //上班正常
                                                    shangBanZhengChang++;
                                                    shangbanzhengchangList.add(setAttendWrappers("上班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneLateHour != null) {
                                                    if (atime > (oneLateHour + dateTime)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                                //下班：签到时间应大于等于dateTime规定签到时间（如果有统计规则，应增加旷工可能《签到时间<规定时间-早退多久算旷工》）
                                            } else {
                                                qiantuijishu++;
                                                if (atime < dateTime) {
                                                    //早退
                                                    zaotuiList.add(setAttendWrappers("早退",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                    zaoTui++;
                                                } else {
                                                    //下班正常
                                                    xiaBanZhengChang++;
                                                    xiabanzhengchangList.add(setAttendWrappers("下班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneEarlyHour != null) {
                                                    if (atime < (dateTime - oneEarlyHour)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case "4"://如果开关开启中
                                    if (attendSet.getAtime4Setother().equals("1")) {
                                        if (attendSet.getAtime4() != null && !attendSet.getAtime4().equals("")) {
                                            //获得规定签到时间毫秒
                                            //  Integer dateTime = DateFormat.getWYQTime(attendSet.getAtime4());
                                            Integer dateTime = null;
                                            String year = atimeStr +" "+attendSet.getAtime4();
                                            Date date1=null;
                                            try{
                                                date1 =sdf2.parse(year);
                                            }catch (Exception e){
                                                e.printStackTrace();
                                            }
                                            long l = date1.getTime();
                                            dateTime = (int)l;
                                            String str = String.valueOf(l);
                                            str = str.substring(0,str.length()-3);
                                            dateTime = Integer.parseInt(str);
                                            if (attendSet.getCommute4().equals("1")) {
                                                qiandaojishu++;
                                                //上班 :签到时间应小于等于dateTime规定签到时间（如果有统计规则，应增加矿工可能《签到时间>规定签到时间+迟到多久算旷工》）
                                                if (atime > dateTime) {
                                                    //迟到
                                                    chiDao++;
                                                    chidaoList.add(setAttendWrappers("迟到",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                } else {
                                                    //上班正常
                                                    shangBanZhengChang++;
                                                    shangbanzhengchangList.add(setAttendWrappers("上班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneLateHour != null) {
                                                    if (atime > (oneLateHour + dateTime)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                                //下班：签到时间应大于等于dateTime规定签到时间（如果有统计规则，应增加旷工可能《签到时间<规定时间-早退多久算旷工》）
                                            } else {
                                                qiantuijishu++;
                                                if (atime < dateTime) {
                                                    //早退
                                                    zaotuiList.add(setAttendWrappers("早退",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                    zaoTui++;
                                                } else {
                                                    //下班正常
                                                    xiaBanZhengChang++;
                                                    xiabanzhengchangList.add(setAttendWrappers("下班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneEarlyHour != null) {
                                                    if (atime < (dateTime - oneEarlyHour)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case "5"://如果开关开启中
                                    if (attendSet.getAtime5Setother().equals("1")) {
                                        if (attendSet.getAtime5() != null && !attendSet.getAtime5().equals("")) {
                                            //获得规定签到时间毫秒
                                            // Integer dateTime = DateFormat.getWYQTime(attendSet.getAtime5());
                                            Integer dateTime = null;
                                            String year = atimeStr +" "+attendSet.getAtime5();
                                            Date date1=null;
                                            try{
                                                date1 =sdf2.parse(year);
                                            }catch (Exception e){
                                                e.printStackTrace();
                                            }
                                            long l = date1.getTime();
                                            dateTime = (int)l;
                                            String str = String.valueOf(l);
                                            str = str.substring(0,str.length()-3);
                                            dateTime = Integer.parseInt(str);
                                            if (attendSet.getCommute5().equals("1")) {
                                                qiandaojishu++;
                                                //上班 :签到时间应小于等于dateTime规定签到时间（如果有统计规则，应增加矿工可能《签到时间>规定签到时间+迟到多久算旷工》）
                                                if (atime > dateTime) {
                                                    //迟到
                                                    chiDao++;
                                                    chidaoList.add(setAttendWrappers("迟到",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                } else {
                                                    //上班正常
                                                    shangBanZhengChang++;
                                                    shangbanzhengchangList.add(setAttendWrappers("上班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneLateHour != null) {
                                                    if (atime > (oneLateHour + dateTime)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                                //下班：签到时间应大于等于dateTime规定签到时间（如果有统计规则，应增加旷工可能《签到时间<规定时间-早退多久算旷工》）
                                            } else {
                                                qiantuijishu++;
                                                if (atime < dateTime) {
                                                    //早退
                                                    zaotuiList.add(setAttendWrappers("早退", sdf.format(attend.getDate()), DateFormat.getStrTime(atime)));
                                                    zaoTui++;
                                                } else {
                                                    //下班正常
                                                    xiaBanZhengChang++;
                                                    xiabanzhengchangList.add(setAttendWrappers("下班准时",sdf.format(attend.getDate()), DateFormat.getStrTime(atime)));
                                                }
                                                if (oneEarlyHour != null) {
                                                    if (atime < (dateTime - oneEarlyHour)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case "6"://如果开关开启中
                                    if (attendSet.getAtime6Setother().equals("1")) {
                                        if (attendSet.getAtime6() != null && !attendSet.getAtime6().equals("")) {
                                            //获得规定签到时间毫秒
                                            // Integer dateTime = DateFormat.getWYQTime(attendSet.getAtime6());
                                            Integer dateTime = null;
                                            String year = atimeStr +" "+attendSet.getAtime6();
                                            Date date1=null;
                                            try{
                                                date1 =sdf2.parse(year);
                                            }catch (Exception e){
                                                e.printStackTrace();
                                            }
                                            long l = date1.getTime();
                                            dateTime = (int)l;
                                            String str = String.valueOf(l);
                                            str = str.substring(0,str.length()-3);
                                            dateTime = Integer.parseInt(str);
                                            if (attendSet.getCommute6().equals("1")) {
                                                qiandaojishu++;
                                                //上班 :签到时间应小于等于dateTime规定签到时间（如果有统计规则，应增加矿工可能《签到时间>规定签到时间+迟到多久算旷工》）
                                                if (atime > dateTime) {
                                                    //迟到
                                                    chiDao++;
                                                    chidaoList.add(setAttendWrappers("迟到",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                } else {
                                                    //上班正常
                                                    shangBanZhengChang++;
                                                    shangbanzhengchangList.add(setAttendWrappers("上班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneLateHour != null) {
                                                    if (atime > (oneLateHour + dateTime)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                                //下班：签到时间应大于等于dateTime规定签到时间（如果有统计规则，应增加旷工可能《签到时间<规定时间-早退多久算旷工》）
                                            } else {
                                                qiantuijishu++;
                                                if (atime < dateTime) {
                                                    //早退
                                                    zaotuiList.add(setAttendWrappers("早退",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                    zaoTui++;
                                                } else {
                                                    //下班正常
                                                    xiaBanZhengChang++;
                                                    xiabanzhengchangList.add(setAttendWrappers("下班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneEarlyHour != null) {
                                                    if (atime < (dateTime - oneEarlyHour)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                            }
                        }
                        if(sb!=null&&sb.length()>0){
                            //获得未签到的时间
                            if(yingqiandao!=null&&yingqiandao.size()>0){
                                for(int f=0;f<yingqiandao.size();f++){
                                    String type=yingqiandao.get(f);
                                    if(!sb.toString().contains(type)){
                                        weiqiandaoList.add(setAttendWrappers("未签到",sdf.format(attends.get(0).getDate()),getTimeByAttendSetType(attendSet,type)));
                                    }
                                }
                            }
                            //获得未签退时间
                            if(yingqiantui!=null&&yingqiantui.size()>0){
                                for(int f=0;f<yingqiantui.size();f++){
                                    String type=yingqiantui.get(f);
                                    if(!sb.toString().contains(type)){
                                        weiqiantuiList.add(setAttendWrappers("未签退",sdf.format(attends.get(0).getDate()),getTimeByAttendSetType(attendSet,type)));
                                    }
                                }
                            }
                        }
                        //迟到早退矿工
                        if (kuanggong == true) {
                            kuangGong++;
                            kuanggongList.add(setAttendWrappers("旷工",sdf.format(attends.get(0).getDate()),null));
                        }
                        //未签到数
                        weiQianDao = weiQianDao + (qiandaocishu - qiandaojishu);
                        //未签退数
                        weiQianTui = weiQianTui + (qiantuicishu - qiantuijishu);
                        //如果应签到次数-正常上班=0，下班正常同上，则全勤
                        if (qiandaocishu - shangBanZhengChang == 0 && qiantuicishu - xiaBanZhengChang == 0) {
                            quanQin = quanQin+1;
                            quanqinList.add(setAttendWrappers("全勤",sdf.format(attends.get(0).getDate()),null));
                        }
                    }
                }
                shiJiChuqin = uidAttendList.size();
                //通过uid获取用户名和公司名
                Map<String, String> userAndDeptName = attendMapper.getUserNameAndDeptNameByUid(uid);
                String userId = userAndDeptName.get("userid");
                //获取在当前时间内的出差
                AttendBase attendBaseChuchai=getChuChai(userId, beginDate, endDate);
                chuChai=attendBaseChuchai.getChuChaiDouble();
                chuchaiList=attendBaseChuchai.getChuChaiList();
                //获取在当前时间内的请假
                AttendBase attendBaseQingjia=null;
                //getQingJia(userId, beginDate, endDate);
                qingJia=attendBaseQingjia.getQingJiaDouble();
                qingjiaList=attendBaseQingjia.getQingJiaList();
                //获取在当前时间内的加班
                AttendBase attendBaseJiaban = getJiaBan(userId, beginDate, endDate);
                jiaBan=attendBaseJiaban.getJiaBanDouble();
                jiabanList=attendBaseJiaban.getJiaBanList();
                //获取在当前时间内的外出
                AttendBase attendBaseWaiChu = getWaiChu(userId, beginDate, endDate);
                waiChu=attendBaseWaiChu.getWaiChuDouble();
                waichuList=attendBaseWaiChu.getWaiChuList();
                //装配
                AttendBase attendBase = new AttendBase();
                attendBase.setUid(uid);
                attendBase.setUserName(userAndDeptName.get("username"));

                attendBase.setChiDao(chiDao);
                attendBase.setKuangGong(kuangGong);
                attendBase.setQuanQin(quanQin);
                attendBase.setWeiQianDao(weiQianDao);
                attendBase.setWeiQianTui(weiQianTui);
                attendBase.setYingChuQin(yingChuQin);
                attendBase.setShiJiChuqin(shiJiChuqin);
                attendBase.setZaoTui(zaoTui);
                attendBase.setDeptName(userAndDeptName.get("deptname"));
                attendBase.setUid(uid);
                attendBase.setUserName(userAndDeptName.get("username"));
                attendBase.setShangBanZhengChang(shangBanZhengChang);
                attendBase.setXiaBanZhengChang(xiaBanZhengChang);
                attendBase.setWaiChuDouble(waiChu);
                attendBase.setQingJiaDouble(qingJia);
                attendBase.setJiaBanDouble(jiaBan);
                attendBase.setChuChaiDouble(chuChai);
                attendBase.setSheBeiYiChang(shebeiyichang.size());
                attendBase.setWaiQin(waiQin);

                attendBase.setChiDaoList(chidaoList);
                attendBase.setZaoTuiList(zaotuiList);
                attendBase.setQuanQinListLr(quanqinList);
                attendBase.setShangBanZhengChangList(shangbanzhengchangList);
                attendBase.setXiaBanZhengChangList(xiabanzhengchangList);
                attendBase.setWeiQianDaoList(weiqiandaoList);
                attendBase.setWeiQianTuiList(weiqiantuiList);
                attendBase.setKuanggongList(kuanggongList);
                attendBase.setWaiChuList(waichuList);
                attendBase.setQingJiaList(qingjiaList);
                attendBase.setJiaBanList(jiabanList);
                attendBase.setChuChaiList(chuchaiList);
                attendBase.setShebeiyichangList(shebeiyichang);

                //如果oneUid有值，代表查看详情

                attendBase.setChuchaixiangqing(attendBaseChuchai.getChuchaixiangqing());
                attendBase.setJiabanxiangqing(attendBaseJiaban.getJiabanxiangqing());
                attendBase.setWaichuxiangqing(attendBaseWaiChu.getWaichuxiangqing());
                attendBase.setQingjiaxiangqing(attendBaseQingjia.getQingjiaxiangqing());
                attendBase.setWaiqinList(waiqinList);
                attendBase.setShebeiyichangList(shebeiyichang);
                List<List<AttendWrappers>> shangxiabanchaxun=new ArrayList<>();
                shangxiabanchaxun.add(chidaoList);
                shangxiabanchaxun.add(zaotuiList);
                shangxiabanchaxun.add(quanqinList);
                shangxiabanchaxun.add(shangbanzhengchangList);
                shangxiabanchaxun.add(xiabanzhengchangList);
                shangxiabanchaxun.add(weiqiandaoList);
                shangxiabanchaxun.add(weiqiantuiList);
                shangxiabanchaxun.add(kuanggongList);
                attendBase.setShangxiabanchaxun(shangxiabanchaxun);


                attendBaseList.add(attendBase);
            }
        }

        *//*ToJson toJson=new ToJson();
        toJson.setObj(attendBaseList);
        toJson.setFlag(0);*//*
        AttendSetWrappers wrappers = new AttendSetWrappers();
        wrappers.setFlag(true);
        wrappers.setStatus(true);
        wrappers.setData(attendBaseList);
        wrappers.setTotleNum(total);
        if(attendBaseList.size()>0){
            wrappers.setMsg("查询成功");
        }else{
            wrappers.setMsg("查询无数据");
        }
        return wrappers;

    }
*/
    //详情导出
    public ToJson exporAttendExcel(Integer dutyType, Integer deptId,
                                   String beginDate, String endDate, Integer pageNo, Integer pageSize, Integer oneUid,
                                   HttpServletRequest req, HttpServletResponse response) {
        /*ToJson json = new ToJson();
        List<AttendBase> attendBaseList = new ArrayList<>();
        List<AttendWrappers> kaoqinList = new ArrayList<>();
        List<AttendWrappers> kaoqinList2 = new ArrayList<>();
        //用于格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //存储已经查到的attendset
        List<AttendSet> dutyTypeList = new ArrayList<>();
        //1、查询出符合条件的人员
        Map<String, Object> map = new HashMap<>();
        map.put("dutyType", dutyType);
        map.put("deptId", deptId);
        map.put("beginDate", beginDate);
        map.put("endDate", endDate);
        map.put("uid",oneUid);
        Integer total=userDutyMapper.getTotalByMap(map);
        Integer startNum=null;
        Integer endNum=null;
        if(pageNo!=null&&pageSize!=null){
            startNum=(pageNo-1)*pageSize;
            endNum=pageSize;
        }
        map.put("startNum",startNum);
        map.put("endNum",endNum);
        List<List<UserDuty>> userDutyList = getUserDutyList(map);//获得多个人员的排班
        if (userDutyList != null && userDutyList.size() > 0) { //遍历每一个人的排班
            for (int i = 0; i < userDutyList.size(); i++) {
                //是否需要查询attendSet表？
                boolean isAttendSet = true;
                //此uid用户的userDuty表，用这个数组查询考勤记录
                List<UserDuty> userDuties = userDutyList.get(i);
                Integer yingChuQin = 0;//应出勤天数
                Integer shangBanZhengChang = 0;//上班正常天数
                Integer xiaBanZhengChang = 0;//下班正常天数
                Integer weiQianDao = 0;//未签到天数
                Integer weiQianTui = 0;//未签退天数
                Integer chiDao = 0;//迟到天数
                Integer zaoTui = 0;//早退天数
                Integer sheBeiYiChang = 0;//異常
                Integer waiQin = 0;//外勤天数
                Double jiaBan = 0.0;//加班天数
                Integer zhiBan = 0;//值班天数
                Double qingJia = 0.0;//请假天数
                Double waiChu = 0.0;//外出天数
                Integer shiJiChuqin = 0;//实际出勤天数
                Integer kuangGong = 0;//旷工天数
                Integer quanQin = 0;//全勤天数
                Double chuChai = 0.0;//出差天数
                List<AttendWrappers> kuanggongList = new ArrayList<>();
                List<AttendWrappers> weiqiandaoList = new ArrayList<>();
                List<AttendWrappers> weiqiantuiList = new ArrayList<>();
                List<AttendWrappers> chidaoList = new ArrayList<>();
                List<AttendWrappers> zaotuiList = new ArrayList<>();
                List<AttendWrappers> yichangList = new ArrayList<>();
                List<AttendWrappers> qingjiaList = new ArrayList<>();
                List<AttendWrappers> waichuList = new ArrayList<>();
                List<AttendWrappers> jiabanList = new ArrayList<>();
                List<AttendWrappers> chuchaiList = new ArrayList<>();
                List<AttendWrappers> shangbanzhengchangList=new ArrayList<>();
                List<AttendWrappers> xiabanzhengchangList=new ArrayList<>();
                List<AttendWrappers> quanqinList=new ArrayList<>();
                List<BaseAttend> shebeiyichang=new ArrayList<>();
                List<Attend> waiqinList=new ArrayList<>();
                yingChuQin = userDuties.size();
                //当前list都是同一个uid，同一个dutyType
                Integer uid = userDuties.get(0).getUid();
                Integer dutytype = userDuties.get(0).getDutyType();
                //查询当前人员所在的部门是否有统计规则
                List<AttendRule> attendRuleList = attendRuleMapper.getAttendRuleByDept(deptId);
                AttendRule attendRule = null;
                //考虑全部部门情况
                if (attendRuleList != null && attendRuleList.size() >= 1) {
                    attendRule = attendRuleList.get(0);
                }
                //定义单次迟到早退多久算旷工
                Integer oneLateHour = null;
                Integer oneEarlyHour = null;
                //如果有统计规则
                if (attendRule != null) {
                    //单次迟到多久算矿工
                    oneLateHour = attendRule.getOneLateHour();
                    //单次早退多久算矿工
                    oneEarlyHour = attendRule.getOneEarlyHour();
                }
                //考勤设置表
                AttendSet attendSet = null;
                //查看是否查询过此考勤设置类型记录
                if (dutyTypeList != null && dutyTypeList.size() == 0) {
                    attendSet = attendSetMapper.queryAttendSetId(dutytype);
                    dutyTypeList.add(attendSet);
                }
                //如果有这个考勤表在不要再查询数据库
                for (AttendSet attendSet1 : dutyTypeList) {
                    if (attendSet1.getSid() == dutytype) {
                        attendSet = attendSet1;
                        isAttendSet = false;
                        break;
                    }
                }
                //当考勤id发生变化时再次查询新表
                if (isAttendSet == true) {
                    attendSet = attendSetMapper.queryAttendSetId(dutytype);
                }
                //此人的考勤记录（1天可能会有多个记录  上下班）
                List<Attend> attendList = attendMapper.getAttendListByUidAndDates(uid, userDuties);
                //定义Set去重时间
                Set<Date> attendDateSet = new HashSet<>();
                if (attendList != null && attendList.size() > 0) {
                    for (int a = 0; a < attendList.size(); a++) {
                        attendDateSet.add(attendList.get(a).getDate());
                    }
                }
                //定义每一个用户attend考勤，区分每一天（通过时间分组）
                List<List<Attend>> uidAttendList = new ArrayList<>();
                //去重后转为list
                List<Date> attendDateList = new ArrayList<>(attendDateSet);
                if (attendDateList != null && attendDateList.size() > 0) {
                    for (int b = 0; b < attendDateList.size(); b++) {
                        Date date1 = attendDateList.get(b);
                        List<Attend> attends = new ArrayList<>();
                        for (int c = 0; c < attendList.size(); c++) {
                            if (attendList.get(c).getDate().compareTo(date1) == 0) {
                                attends.add(attendList.get(c));
                            }
                        }
                        if (attends != null && attends.size() > 0) {
                            uidAttendList.add(attends);
                        }
                    }
                }
                //装配开关属性
                attendSet = setAttendSet(attendSet);
                String attendStr = attendSet.toString();
                //获取应签到次数
                Map<String, List<String>> daKa = getQianDaoCiShu(attendSet);
                List<String> yingqiandao=daKa.get("yingqiandao");
                List<String> yingqiantui=daKa.get("yingqiantui");
                int qiandaocishu = yingqiandao.size();
                int qiantuicishu = yingqiantui.size();
                //查找是否有没有签到的天数
                for (int e = 0; e < userDuties.size(); e++) {
                    String dutyDate = userDuties.get(e).getDutyDate();
                    boolean nokuanggong = false;
                    for (int f = 0; f < uidAttendList.size(); f++) {
                        if (sdf.format(uidAttendList.get(f).get(0).getDate()).equals(dutyDate)) {
                            nokuanggong = true;
                            break;
                        }
                    }
                    if (nokuanggong == false) {
                        kuangGong++;
                        //矿工
                        AttendWrappers kg = new AttendWrappers();
                        kg.setDate(dutyDate);
                        kg.setWeek(getWeekByData(dutyDate));
                        kg.setType("旷工");
                        weiQianDao = weiQianDao + qiandaocishu;
                        weiQianTui = weiQianTui + qiantuicishu;
                        //未签
                        Map<String,List<AttendWrappers>> weiQianMap=getWeiQian(attendSet,dutyDate);
                        //未签到
                        weiqiandaoList=weiQianMap.get("weiQianDao");
                        //未签退
                        weiqiantuiList=weiQianMap.get("weiQianTui");
                    }
                }
                //遍历这个用户的所有天数
                if (uidAttendList != null && uidAttendList.size() > 0) {
                    for (int d = 0; d < uidAttendList.size(); d++) {
                        //获得每一天的考勤
                        List<Attend> attends = uidAttendList.get(d);
                        boolean kuanggong = false;//是否矿工
                        int qiandaojishu = 0;
                        int qiantuijishu = 0;
                        //获取当天的所有签到类型
                        StringBuffer sb=new StringBuffer();
                        for (Attend attend : attends) {
                            //当前考勤记录 签到 时间
                            Integer atime = attend.getAtime();
                            String atimeStr = sdf.format(new Date(Long.valueOf(atime+"000")));
                            //当前签到次数
                            String type = attend.getType();
                            //装配签到次数，用来遍历是否有未签到未签退的
                            sb.append(type);
                            //设备异常（b）
                            shebeiyichang=myAttendUnitException(beginDate,endDate,uid,req);
                            switch (type) {
                                case "0":waiQin++;waiqinList.add(attend);break;
                                case "1":
                                    //如果开关开启中
                                    if (attendSet.getAtime1Setother().equals("1")) {
                                        if (attendSet.getAtime1() != null && !attendSet.getAtime1().equals("")) {
                                            //获得规定签到时间毫秒
                                            // Integer dateTime = DateFormat.getWYQTime(attendSet.getAtime1());
                                            Integer dateTime = null;
                                            String year = atimeStr +" "+attendSet.getAtime1();
                                            Date date1=null;
                                            try{
                                                date1 =sdf2.parse(year);
                                            }catch (Exception e){
                                                e.printStackTrace();
                                            }
                                            long l = date1.getTime();
                                            dateTime = (int)l;
                                            String str = String.valueOf(l);
                                            str = str.substring(0,str.length()-3);
                                            dateTime = Integer.parseInt(str);
                                            if (attendSet.getCommute1().equals("1")) {
                                                qiandaojishu++;
                                                //上班 :签到时间应小于等于dateTime规定签到时间（如果有统计规则，应增加矿工可能《签到时间>规定签到时间+迟到多久算旷工》）
                                                if (atime > dateTime) {
                                                    //迟到
                                                    chiDao++;
                                                    chidaoList.add(setAttendWrappers("迟到",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                } else {
                                                    //上班正常
                                                    shangBanZhengChang++;
                                                    shangbanzhengchangList.add(setAttendWrappers("上班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneLateHour != null) {
                                                    if (atime > (oneLateHour + dateTime)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                                //下班：签到时间应大于等于dateTime规定签到时间（如果有统计规则，应增加旷工可能《签到时间<规定时间-早退多久算旷工》）
                                            } else {
                                                qiantuijishu++;
                                                if (atime < dateTime) {
                                                    //早退
                                                    zaotuiList.add(setAttendWrappers("早退",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                    zaoTui++;
                                                } else {
                                                    //下班正常
                                                    xiaBanZhengChang++;
                                                    xiabanzhengchangList.add(setAttendWrappers("下班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneEarlyHour != null) {
                                                    if (atime < (dateTime - oneEarlyHour)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case "2"://如果开关开启中
                                    if (attendSet.getAtime2Setother().equals("1")) {
                                        if (attendSet.getAtime2() != null && !attendSet.getAtime2().equals("")) {
                                            //获得规定签到时间毫秒
                                            // Integer dateTime = DateFormat.getWYQTime(attendSet.getAtime2());
                                            Integer dateTime = null;
                                            String year = atimeStr +" "+attendSet.getAtime2();
                                            Date date1=null;
                                            try{
                                                date1 =sdf2.parse(year);
                                            }catch (Exception e){
                                                e.printStackTrace();
                                            }
                                            long l = date1.getTime();
                                            dateTime = (int)l;
                                            String str = String.valueOf(l);
                                            str = str.substring(0,str.length()-3);
                                            dateTime = Integer.parseInt(str);
                                            if (attendSet.getCommute2().equals("1")) {
                                                qiandaojishu++;
                                                //上班 :签到时间应小于等于dateTime规定签到时间（如果有统计规则，应增加矿工可能《签到时间>规定签到时间+迟到多久算旷工》）
                                                if (atime > dateTime) {
                                                    //迟到
                                                    chiDao++;
                                                    chidaoList.add(setAttendWrappers("迟到",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                } else {
                                                    //上班正常
                                                    shangBanZhengChang++;
                                                    shangbanzhengchangList.add(setAttendWrappers("上班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneLateHour != null) {
                                                    if (atime > (oneLateHour + dateTime)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                                //下班：签到时间应大于等于dateTime规定签到时间（如果有统计规则，应增加旷工可能《签到时间<规定时间-早退多久算旷工》）
                                            } else {
                                                qiantuijishu++;
                                                if (atime < dateTime) {
                                                    //早退
                                                    zaotuiList.add(setAttendWrappers("早退",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                    zaoTui++;
                                                } else {
                                                    //下班正常
                                                    xiaBanZhengChang++;
                                                    xiabanzhengchangList.add(setAttendWrappers("下班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneEarlyHour != null) {
                                                    if (atime < (dateTime - oneEarlyHour)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case "3"://如果开关开启中
                                    if (attendSet.getAtime3Setother().equals("1")) {
                                        if (attendSet.getAtime3() != null && !attendSet.getAtime3().equals("")) {
                                            //获得规定签到时间毫秒
                                            //  Integer dateTime = DateFormat.getWYQTime(attendSet.getAtime3());
                                            Integer dateTime = null;
                                            String year = atimeStr +" "+attendSet.getAtime3();
                                            Date date1=null;
                                            try{
                                                date1 =sdf2.parse(year);
                                            }catch (Exception e){
                                                e.printStackTrace();
                                            }
                                            long l = date1.getTime();
                                            dateTime = (int)l;
                                            String str = String.valueOf(l);
                                            str = str.substring(0,str.length()-3);
                                            dateTime = Integer.parseInt(str);
                                            if (attendSet.getCommute3().equals("1")) {
                                                qiandaojishu++;
                                                //上班 :签到时间应小于等于dateTime规定签到时间（如果有统计规则，应增加矿工可能《签到时间>规定签到时间+迟到多久算旷工》）
                                                if (atime > dateTime) {
                                                    //迟到
                                                    chiDao++;
                                                    chidaoList.add(setAttendWrappers("迟到",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                } else {
                                                    //上班正常
                                                    shangBanZhengChang++;
                                                    shangbanzhengchangList.add(setAttendWrappers("上班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneLateHour != null) {
                                                    if (atime > (oneLateHour + dateTime)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                                //下班：签到时间应大于等于dateTime规定签到时间（如果有统计规则，应增加旷工可能《签到时间<规定时间-早退多久算旷工》）
                                            } else {
                                                qiantuijishu++;
                                                if (atime < dateTime) {
                                                    //早退
                                                    zaotuiList.add(setAttendWrappers("早退",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                    zaoTui++;
                                                } else {
                                                    //下班正常
                                                    xiaBanZhengChang++;
                                                    xiabanzhengchangList.add(setAttendWrappers("下班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneEarlyHour != null) {
                                                    if (atime < (dateTime - oneEarlyHour)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case "4"://如果开关开启中
                                    if (attendSet.getAtime4Setother().equals("1")) {
                                        if (attendSet.getAtime4() != null && !attendSet.getAtime4().equals("")) {
                                            //获得规定签到时间毫秒
                                            //  Integer dateTime = DateFormat.getWYQTime(attendSet.getAtime4());
                                            Integer dateTime = null;
                                            String year = atimeStr +" "+attendSet.getAtime4();
                                            Date date1=null;
                                            try{
                                                date1 =sdf2.parse(year);
                                            }catch (Exception e){
                                                e.printStackTrace();
                                            }
                                            long l = date1.getTime();
                                            dateTime = (int)l;
                                            String str = String.valueOf(l);
                                            str = str.substring(0,str.length()-3);
                                            dateTime = Integer.parseInt(str);
                                            if (attendSet.getCommute4().equals("1")) {
                                                qiandaojishu++;
                                                //上班 :签到时间应小于等于dateTime规定签到时间（如果有统计规则，应增加矿工可能《签到时间>规定签到时间+迟到多久算旷工》）
                                                if (atime > dateTime) {
                                                    //迟到
                                                    chiDao++;
                                                    chidaoList.add(setAttendWrappers("迟到",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                } else {
                                                    //上班正常
                                                    shangBanZhengChang++;
                                                    shangbanzhengchangList.add(setAttendWrappers("上班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneLateHour != null) {
                                                    if (atime > (oneLateHour + dateTime)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                                //下班：签到时间应大于等于dateTime规定签到时间（如果有统计规则，应增加旷工可能《签到时间<规定时间-早退多久算旷工》）
                                            } else {
                                                qiantuijishu++;
                                                if (atime < dateTime) {
                                                    //早退
                                                    zaotuiList.add(setAttendWrappers("早退",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                    zaoTui++;
                                                } else {
                                                    //下班正常
                                                    xiaBanZhengChang++;
                                                    xiabanzhengchangList.add(setAttendWrappers("下班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneEarlyHour != null) {
                                                    if (atime < (dateTime - oneEarlyHour)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case "5"://如果开关开启中
                                    if (attendSet.getAtime5Setother().equals("1")) {
                                        if (attendSet.getAtime5() != null && !attendSet.getAtime5().equals("")) {
                                            //获得规定签到时间毫秒
                                            // Integer dateTime = DateFormat.getWYQTime(attendSet.getAtime5());
                                            Integer dateTime = null;
                                            String year = atimeStr +" "+attendSet.getAtime5();
                                            Date date1=null;
                                            try{
                                                date1 =sdf2.parse(year);
                                            }catch (Exception e){
                                                e.printStackTrace();
                                            }
                                            long l = date1.getTime();
                                            dateTime = (int)l;
                                            String str = String.valueOf(l);
                                            str = str.substring(0,str.length()-3);
                                            dateTime = Integer.parseInt(str);
                                            if (attendSet.getCommute5().equals("1")) {
                                                qiandaojishu++;
                                                //上班 :签到时间应小于等于dateTime规定签到时间（如果有统计规则，应增加矿工可能《签到时间>规定签到时间+迟到多久算旷工》）
                                                if (atime > dateTime) {
                                                    //迟到
                                                    chiDao++;
                                                    chidaoList.add(setAttendWrappers("迟到",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                } else {
                                                    //上班正常
                                                    shangBanZhengChang++;
                                                    shangbanzhengchangList.add(setAttendWrappers("上班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneLateHour != null) {
                                                    if (atime > (oneLateHour + dateTime)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                                //下班：签到时间应大于等于dateTime规定签到时间（如果有统计规则，应增加旷工可能《签到时间<规定时间-早退多久算旷工》）
                                            } else {
                                                qiantuijishu++;
                                                if (atime < dateTime) {
                                                    //早退
                                                    zaotuiList.add(setAttendWrappers("早退", sdf.format(attend.getDate()), DateFormat.getStrTime(atime)));
                                                    zaoTui++;
                                                } else {
                                                    //下班正常
                                                    xiaBanZhengChang++;
                                                    xiabanzhengchangList.add(setAttendWrappers("下班准时",sdf.format(attend.getDate()), DateFormat.getStrTime(atime)));
                                                }
                                                if (oneEarlyHour != null) {
                                                    if (atime < (dateTime - oneEarlyHour)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case "6"://如果开关开启中
                                    if (attendSet.getAtime6Setother().equals("1")) {
                                        if (attendSet.getAtime6() != null && !attendSet.getAtime6().equals("")) {
                                            //获得规定签到时间毫秒
                                            // Integer dateTime = DateFormat.getWYQTime(attendSet.getAtime6());
                                            Integer dateTime = null;
                                            String year = atimeStr +" "+attendSet.getAtime6();
                                            Date date1=null;
                                            try{
                                                date1 =sdf2.parse(year);
                                            }catch (Exception e){
                                                e.printStackTrace();
                                            }
                                            long l = date1.getTime();
                                            dateTime = (int)l;
                                            String str = String.valueOf(l);
                                            str = str.substring(0,str.length()-3);
                                            dateTime = Integer.parseInt(str);
                                            if (attendSet.getCommute6().equals("1")) {
                                                qiandaojishu++;
                                                //上班 :签到时间应小于等于dateTime规定签到时间（如果有统计规则，应增加矿工可能《签到时间>规定签到时间+迟到多久算旷工》）
                                                if (atime > dateTime) {
                                                    //迟到
                                                    chiDao++;
                                                    chidaoList.add(setAttendWrappers("迟到",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                } else {
                                                    //上班正常
                                                    shangBanZhengChang++;
                                                    shangbanzhengchangList.add(setAttendWrappers("上班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneLateHour != null) {
                                                    if (atime > (oneLateHour + dateTime)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                                //下班：签到时间应大于等于dateTime规定签到时间（如果有统计规则，应增加旷工可能《签到时间<规定时间-早退多久算旷工》）
                                            } else {
                                                qiantuijishu++;
                                                if (atime < dateTime) {
                                                    //早退
                                                    zaotuiList.add(setAttendWrappers("早退",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                    zaoTui++;
                                                } else {
                                                    //下班正常
                                                    xiaBanZhengChang++;
                                                    xiabanzhengchangList.add(setAttendWrappers("下班准时",sdf.format(attend.getDate()),DateFormat.getStrTime(atime)));
                                                }
                                                if (oneEarlyHour != null) {
                                                    if (atime < (dateTime - oneEarlyHour)) {
                                                        kuanggong = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                            }
                        }
                        if(sb!=null&&sb.length()>0){
                            //获得未签到的时间
                            if(yingqiandao!=null&&yingqiandao.size()>0){
                                for(int f=0;f<yingqiandao.size();f++){
                                    String type=yingqiandao.get(f);
                                    if(!sb.toString().contains(type)){
                                        weiqiandaoList.add(setAttendWrappers("未签到",sdf.format(attends.get(0).getDate()),getTimeByAttendSetType(attendSet,type)));
                                    }
                                }
                            }
                            //获得未签退时间
                            if(yingqiantui!=null&&yingqiantui.size()>0){
                                for(int f=0;f<yingqiantui.size();f++){
                                    String type=yingqiantui.get(f);
                                    if(!sb.toString().contains(type)){
                                        weiqiantuiList.add(setAttendWrappers("未签退",sdf.format(attends.get(0).getDate()),getTimeByAttendSetType(attendSet,type)));
                                    }
                                }
                            }
                        }
                        //迟到早退矿工
                        if (kuanggong == true) {
                            kuangGong++;
                            kuanggongList.add(setAttendWrappers("旷工",sdf.format(attends.get(0).getDate()),null));
                        }
                        //未签到数
                        weiQianDao = weiQianDao + (qiandaocishu - qiandaojishu);
                        //未签退数
                        weiQianTui = weiQianTui + (qiantuicishu - qiantuijishu);
                        //如果应签到次数-正常上班=0，下班正常同上，则全勤
                        if (qiandaocishu - shangBanZhengChang == 0 && qiantuicishu - xiaBanZhengChang == 0) {
                            quanQin = quanQin+1;
                            quanqinList.add(setAttendWrappers("全勤",sdf.format(attends.get(0).getDate()),null));
                        }
                    }
                }
                shiJiChuqin = uidAttendList.size();
                //通过uid获取用户名和公司名
                Map<String, String> userAndDeptName = attendMapper.getUserNameAndDeptNameByUid(uid);
                String userId = userAndDeptName.get("userid");
                //获取在当前时间内的出差
                AttendBase attendBaseChuchai=getChuChai(userId, beginDate, endDate);
                chuChai=attendBaseChuchai.getChuChaiDouble();
                chuchaiList=attendBaseChuchai.getChuChaiList();
                //获取在当前时间内的请假
                AttendBase attendBaseQingjia=null;
                //getQingJia(userId, beginDate, endDate);
                qingJia=attendBaseQingjia.getQingJiaDouble();
                qingjiaList=attendBaseQingjia.getQingJiaList();
                //获取在当前时间内的加班
                AttendBase attendBaseJiaban = getJiaBan(userId, beginDate, endDate);
                jiaBan=attendBaseJiaban.getJiaBanDouble();
                jiabanList=attendBaseJiaban.getJiaBanList();
                //获取在当前时间内的外出
                AttendBase attendBaseWaiChu = getWaiChu(userId, beginDate, endDate);
                waiChu=attendBaseWaiChu.getWaiChuDouble();
                waichuList=attendBaseWaiChu.getWaiChuList();
                //装配
                AttendBase attendBase = new AttendBase();
                attendBase.setUid(uid);
                attendBase.setUserName(userAndDeptName.get("username"));

                attendBase.setChiDao(chiDao);
                attendBase.setKuangGong(kuangGong);
                attendBase.setQuanQin(quanQin);
                attendBase.setWeiQianDao(weiQianDao);
                attendBase.setWeiQianTui(weiQianTui);
                attendBase.setYingChuQin(yingChuQin);
                attendBase.setShiJiChuqin(shiJiChuqin);
                attendBase.setZaoTui(zaoTui);
                attendBase.setDeptName(userAndDeptName.get("deptname"));
                attendBase.setUid(uid);
                attendBase.setUserName(userAndDeptName.get("username"));
                attendBase.setShangBanZhengChang(shangBanZhengChang);
                attendBase.setXiaBanZhengChang(xiaBanZhengChang);
                attendBase.setWaiChuDouble(waiChu);
                attendBase.setQingJiaDouble(qingJia);
                attendBase.setJiaBanDouble(jiaBan);
                attendBase.setChuChaiDouble(chuChai);
                attendBase.setSheBeiYiChang(shebeiyichang.size());
                attendBase.setWaiQin(waiQin);

                attendBase.setChiDaoList(chidaoList);
                attendBase.setZaoTuiList(zaotuiList);
                attendBase.setQuanQinListLr(quanqinList);
                attendBase.setShangBanZhengChangList(shangbanzhengchangList);
                attendBase.setXiaBanZhengChangList(xiabanzhengchangList);
                attendBase.setWeiQianDaoList(weiqiandaoList);
                attendBase.setWeiQianTuiList(weiqiantuiList);
                attendBase.setKuanggongList(kuanggongList);
                attendBase.setWaiChuList(waichuList);
                attendBase.setQingJiaList(qingjiaList);
                attendBase.setJiaBanList(jiabanList);
                attendBase.setChuChaiList(chuchaiList);
                attendBase.setShebeiyichangList(shebeiyichang);

                //如果oneUid有值，代表查看详情

                attendBase.setChuchaixiangqing(attendBaseChuchai.getChuchaixiangqing());
                attendBase.setJiabanxiangqing(attendBaseJiaban.getJiabanxiangqing());
                attendBase.setWaichuxiangqing(attendBaseWaiChu.getWaichuxiangqing());
                attendBase.setQingjiaxiangqing(attendBaseQingjia.getQingjiaxiangqing());
                attendBase.setWaiqinList(waiqinList);
                attendBase.setShebeiyichangList(shebeiyichang);
                List<List<AttendWrappers>> shangxiabanchaxun=new ArrayList<>();
                shangxiabanchaxun.add(chidaoList);
                shangxiabanchaxun.add(zaotuiList);
                shangxiabanchaxun.add(quanqinList);
                shangxiabanchaxun.add(shangbanzhengchangList);
                shangxiabanchaxun.add(xiabanzhengchangList);
                shangxiabanchaxun.add(weiqiandaoList);
                shangxiabanchaxun.add(weiqiantuiList);
                shangxiabanchaxun.add(kuanggongList);
                attendBase.setShangxiabanchaxun(shangxiabanchaxun);


                attendBaseList.add(attendBase);
                //得到上班，下班，迟到，早退，加班的信息
                for (AttendWrappers attendWrappers : xiabanzhengchangList) {
                    attendWrappers.setUserName(attendBaseList.get(i).getUserName());
                    attendWrappers.setDepartment(attendBaseList.get(i).getDeptName());
                }
                for (AttendWrappers attendWrappers : shangbanzhengchangList) {
                    attendWrappers.setUserName(attendBaseList.get(i).getUserName());
                    attendWrappers.setDepartment(attendBaseList.get(i).getDeptName());
                }
                for (AttendWrappers attendWrappers : chidaoList) {
                    attendWrappers.setUserName(attendBaseList.get(i).getUserName());
                    attendWrappers.setDepartment(attendBaseList.get(i).getDeptName());
                }
                for (AttendWrappers attendWrappers : zaotuiList) {
                    attendWrappers.setUserName(attendBaseList.get(i).getUserName());
                    attendWrappers.setDepartment(attendBaseList.get(i).getDeptName());
                }
                for (AttendWrappers attendWrappers : jiabanList) {
                    attendWrappers.setUserName(attendBaseList.get(i).getUserName());
                    attendWrappers.setDepartment(attendBaseList.get(i).getDeptName());
                }
                for (AttendWrappers attendWrappers : kuanggongList) {
                    attendWrappers.setUserName(attendBaseList.get(i).getUserName());
                    attendWrappers.setDepartment(attendBaseList.get(i).getDeptName());
                }
                kaoqinList.addAll(shangbanzhengchangList);
                kaoqinList.addAll(xiabanzhengchangList);
                kaoqinList.addAll(chidaoList);
                kaoqinList.addAll(zaotuiList);
                kaoqinList.addAll(jiabanList);
                kaoqinList.addAll(kuanggongList);
            }
        }
        try {
            paixu(kaoqinList);
            for (AttendWrappers attendWrappers:kaoqinList) {
                if (attendWrappers.getTime() != null) {
                    attendWrappers.setTime(attendWrappers.getTime().substring(11));
                }
            }
            String[] beanProperty = {"department", "userName","date", "time","week", "type"};
            String[] title = {"部门名称", "员工名称", "日期","时间","工作日", "签到类型"};
            HSSFWorkbook tableWork = ExcelUtil.makeExcelHead("考勤统计详情表", 4);
            HSSFWorkbook excelWork = ExcelUtil.makeSecondHead(tableWork, title);
            HSSFWorkbook workbook = ExcelUtil.exportExcelData(excelWork, kaoqinList, beanProperty);
            OutputStream out = response.getOutputStream();
            String filename = "考勤统计详情表.xls"; //考虑多语言
            filename = FileUtils.encodeDownloadFilename(filename,req.getHeader("user-agent"));
            response.setContentType("text/html;charset=UTF-8");
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("content-disposition", "attachment;filename=" + filename);
            workbook.write(out);
            out.close();
        } catch (Exception e) {
            L.e("EduFixAssetsService selFixAssetsByCond:" + e);
            e.printStackTrace();

        }*/
        ToJson json = null;
        return json;
    }


    //根据类型获取时间
    public String getTimeByAttendSetType(AttendSet attendSet, String type) {
        switch (type) {
            case "1":
                return attendSet.getAtime1();
            case "2":
                return attendSet.getAtime2();
            case "3":
                return attendSet.getAtime3();
            case "4":
                return attendSet.getAtime4();
            case "5":
                return attendSet.getAtime5();
            case "6":
                return attendSet.getAtime6();
        }
        return null;
    }


    public AttendWrappers setLiucheng(String beginTime, String endTime, String dayCount) {
        AttendWrappers attendWrappers = new AttendWrappers();
        attendWrappers.setStartTime(beginTime);
        attendWrappers.setEndTime(endTime);
        attendWrappers.setDayCount(dayCount);
        return attendWrappers;
    }

    //获取外出天数
    public BaseAttend getWaiChu(String userId, String beginDate, String endDate) {
        BaseAttend baseAttendResult = new BaseAttend();
        List<BaseAttend> baseAttendList = new ArrayList<>();
        Double tDays = 0.0;
        List<AttendOut> attendOutList = attendOutMapper.selectAttendOverList(userId, beginDate, endDate);
        for (AttendOut attendLeave : attendOutList) {
            String dbBeginDate = attendLeave.getOutTime1();
            String dbEndDate = attendLeave.getOutTime2();
            String stratTime = beginDate;
            String endTime = endDate + " 59:59:59";
            //如果用户xx开始时间大于搜索的开始时间，那么起始时间为用户时间
            if (getIntegerTime(dbBeginDate) > getIntegerTime(beginDate)) {
                stratTime = dbBeginDate;
            }
            //如果用户xx结束时间小于搜索的开始时间，那么结束时间为用户时间
            if (getIntegerTime(dbEndDate) < getIntegerTime(endDate)) {
                endTime = dbEndDate;
            }
            List<String> days = getDays(stratTime, endTime);
            Double daysDouble = getAttendDays(stratTime, endTime);
            BaseAttend baseAttend = new BaseAttend();
            baseAttend.setAttendDate(days);
            baseAttend.setRunName(attendLeave.getRunName());
            baseAttendList.add(baseAttend);
            tDays += daysDouble;
        }
        baseAttendResult.setAttendList(baseAttendList);
        baseAttendResult.setDays(tDays);
        return baseAttendResult;
    }
    /*public AttendBase getWaiChu(String userId, String beginDate, String endDate) {
        List<AttendWrappers> waiChuList=new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Double dayCount = 0.0;
        if(endDate.equals(DateFormat.getCurrentTime2())){
            endDate = DateFormat.getStrDate(new Date());
        }
        List<AttendOut> attendOutList = attendOutMapper.selectAttendOverList(userId, beginDate, endDate);
        if (attendOutList != null && attendOutList.size() > 0) {
            for (AttendOut attendOut : attendOutList) {
                AttendWrappers waichu=new AttendWrappers();
                String beginTime = attendOut.getOutTime1();
                String endTime = attendOut.getOutTime2();
                try {
                    Date date1 = sdf.parse(beginTime);
                    Date date2 = sdf.parse(endTime);
                    Double day = getDayByDate(date1, date2).doubleValue();
                    dayCount = dayCount + day;
                    waiChuList.add(setLiucheng(beginTime,endTime,day+""));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
        AttendBase attendBase=new AttendBase();
        attendBase.setWaiChuDouble(dayCount);
        attendBase.setWaiChuList(waiChuList);
        attendBase.setWaichuxiangqing(attendOutList);
        return attendBase;
    }*/

    //获取加班天数
    public BaseAttend getJiaBan(String userId, String beginDate, String endDate) {
        BaseAttend baseAttendResult = new BaseAttend();
        List<BaseAttend> baseAttendList = new ArrayList<>();
        Double tDays = 0.0; //天
        List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeMapper.selectAttendanceOvertimeList(userId, beginDate, endDate);
        for (AttendanceOvertime attendLeave : attendanceOvertimeList) {
            Date dbBeginDate = attendLeave.getStartTime();
            Date dbEndDate = attendLeave.getEndTime();
            if (dbBeginDate!=null && dbEndDate !=null){
                String stratTime = beginDate;
                String endTime = endDate + " 59:59:59";
                //如果用户xx开始时间大于搜索的开始时间，那么起始时间为用户时间
                if (getIntegerTime(dbBeginDate) > getIntegerTime(beginDate)) {
                    stratTime = DateFormat.getStrDate(dbBeginDate);
                }
                //如果用户xx结束时间小于搜索的开始时间，那么结束时间为用户时间
                if (getIntegerTime(dbEndDate) < getIntegerTime(endDate)) {
                    endTime = DateFormat.getStrDate(dbEndDate);
                }
                List<String> days = getDays(stratTime, endTime);
                Double daysDouble = getAttendDays(stratTime, endTime);
                BaseAttend baseAttend = new BaseAttend();
                baseAttend.setAttendDate(days);
                baseAttend.setRunName(attendLeave.getRunName());
                baseAttendList.add(baseAttend);
                tDays += daysDouble;
            }else{
                tDays += 1.0;
            }

        }
        baseAttendResult.setAttendList(baseAttendList);
        baseAttendResult.setDays(tDays);
        baseAttendResult.setItem(attendanceOvertimeList.size()); //项
        return baseAttendResult;
    }
    /*public AttendBase getJiaBan(String userId, String beginDate, String endDate) {
        List<AttendWrappers> jiaBanList=new ArrayList<>();
        Double dayCount = 0.0;
        if(endDate.equals(DateFormat.getCurrentTime2())){
            endDate = DateFormat.getStrDate(new Date());
        }
        List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeMapper.selectAttendanceOvertimeList(userId, beginDate, endDate);
        if (attendanceOvertimeList != null && attendanceOvertimeList.size() > 0) {
            for (AttendanceOvertime attendanceOvertime : attendanceOvertimeList) {
                Double day = getDayByDate(attendanceOvertime.getStartTime(), attendanceOvertime.getEndTime()).doubleValue();
                dayCount = dayCount + day;
                jiaBanList.add(setLiucheng(sdf1.format(attendanceOvertime.getStartTime()),sdf1.format(attendanceOvertime.getEndTime()),day+""));
            }
        }
        AttendBase attendBase=new AttendBase();
        attendBase.setJiaBanDouble(dayCount);
        attendBase.setJiaBanList(jiaBanList);
        attendBase.setJiabanxiangqing(attendanceOvertimeList);
        return attendBase;
    }*/

    //获取请假天数
    public BaseAttend getQingJia(String userId, String beginDate, String endDate) {
        BaseAttend baseAttendResult = new BaseAttend();
        List<BaseAttend> baseAttendList = new ArrayList<>();
        Double tDays = 0.0;
        List<AttendLeave> attendLeaveList = attendLeaveMapper.selectAttendLeaveList(userId, beginDate, endDate);
        for (AttendLeave attendLeave : attendLeaveList) {
            Date dbBeginDate = attendLeave.getLeaveDate1();
            Date dbEndDate = attendLeave.getLeaveDate2();
            if (dbBeginDate!=null && dbEndDate!=null){
                String stratTime = beginDate;
                String endTime = endDate + " 23:59:59";
                //如果用户xx开始时间大于搜索的开始时间，那么起始时间为用户时间
                if (getIntegerTime(dbBeginDate) > getIntegerTime(beginDate)) {
                    stratTime = DateFormat.getStrDate(dbBeginDate);
                }
                //如果用户xx结束时间小于搜索的开始时间，那么结束时间为用户时间
                if (getIntegerTime(dbEndDate) < getIntegerTime(endTime)) {
                    endTime = DateFormat.getStrDate(dbEndDate);
                }
                List<String> days = getDays(stratTime, endTime);
                Double daysDouble = getAttendDays(stratTime, endTime);
                BaseAttend baseAttend = new BaseAttend();
                baseAttend.setAttendDate(days);
                baseAttend.setRunName(attendLeave.getRunName());
                baseAttendList.add(baseAttend);
                tDays += daysDouble;
            }else{
                tDays += 1.0;
            }
        }
        baseAttendResult.setAttendList(baseAttendList);
        baseAttendResult.setDays(tDays);
        baseAttendResult.setItem(attendLeaveList.size());
        return baseAttendResult;
    }

    /**
     * @创建作者:李然 Lr
     * @方法描述：获取俩时间之间天数（如果俩时间之间天数余小时>4小时算一天，否则大于1小时小于4小时算0.5天），
     * @创建时间：10:52 2019/3/13
     **/
    public Double getAttendDays(String startTime, String endTime) {
        Double result = 0.0;
        Integer four = 4 * 60 * 60;
        Integer start = getIntegerTime(startTime);
        Integer end = getIntegerTime(endTime);
        Integer cha = end - start;
        Integer day = 0;
        Integer yu = 0;
        if (cha > 24 * 60 * 60) {
            day = cha / (24 * 60 * 60);
            yu = cha - (day * 24 * 60 * 60);
        } else if (cha > 0) {
            yu = cha;
        }
        if (yu > 0) {
            if (yu > four) {
                result = day + 1.0;
            } else if (yu > (60 * 60)) {
                result = day + 0.5;
            } else {
                result = day + 0.0;
            }
        }
        return result;
    }

    /**
     * 获取两个日期之间的所有日期
     *
     * @param startTime 开始日期
     * @param endTime   结束日期
     * @return
     */
    public static List<String> getDays(String startTime, String endTime) {
        if (startTime.length() > 10) {
            startTime = startTime.split(" ")[0];
        }
        if (endTime.length() > 10) {
            endTime = endTime.split(" ")[0];
        }
        // 返回的日期集合
        List<String> days = new ArrayList<String>();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date start = dateFormat.parse(startTime);
            Date end = dateFormat.parse(endTime);

            Calendar tempStart = Calendar.getInstance();
            tempStart.setTime(start);

            Calendar tempEnd = Calendar.getInstance();
            tempEnd.setTime(end);
            tempEnd.add(Calendar.DATE, +1);// 日期加1(包含结束)
            while (tempStart.before(tempEnd)) {
                days.add(dateFormat.format(tempStart.getTime()));
                tempStart.add(Calendar.DAY_OF_YEAR, 1);
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return days;
    }

    /**
     * 将任意类型转换秒级时间戳
     *
     * @param obj
     * @return
     */
    public Integer getIntegerTime(Object obj) {
        if (obj != null) {
            long time = 0;
            if (obj instanceof String) {
                String dateStr = (String) obj;
                if (dateStr.length() > 10) {
                    time = DateFormat.getDate(dateStr).getTime();
                } else {
                    time = DateFormat.getDates(dateStr).getTime();
                }

            }
            if (obj instanceof Date) {
                //不用转了
                Date date = (Date) obj;
                time = date.getTime();

            }
            String str = String.valueOf(time);
            if (str.length() > 10) {
                str = str.substring(0, 10);
            }
            return Integer.parseInt(str);
        }
        return null;
    }

    //获取出差天数
    public BaseAttend getChuChai(String userId, String beginDate, String endDate) {
        BaseAttend baseAttendResult = new BaseAttend();
        List<BaseAttend> baseAttendList = new ArrayList<>();
        Double tDays = 0.0;
        List<AttendEvection> attendEvectionList = attendEvectionMapper.selectAttendEvectionListByUserDd(userId, beginDate, endDate);
        for (AttendEvection attendLeave : attendEvectionList) {
            Date dbBeginDate = attendLeave.getEvectionDate1();
            Date dbEndDate = attendLeave.getEvectionDate2();
            if (dbBeginDate!=null && dbEndDate!=null){
                String stratTime = beginDate;
                String endTime = endDate + " 59:59:59";
                //如果用户xx开始时间大于搜索的开始时间，那么起始时间为用户时间
                if (getIntegerTime(dbBeginDate) > getIntegerTime(beginDate)) {
                    stratTime = DateFormat.getStrDate(dbBeginDate);
                }
                //如果用户xx结束时间小于搜索的开始时间，那么结束时间为用户时间
                if (getIntegerTime(dbEndDate) < getIntegerTime(endDate)) {
                    endTime = DateFormat.getStrDate(dbEndDate);
                }
                List<String> days = getDays(stratTime, endTime);
                Double daysDouble = getAttendDays(stratTime, endTime);
                BaseAttend baseAttend = new BaseAttend();
                baseAttend.setAttendDate(days);
                baseAttend.setRunName(attendLeave.getRunName());
                baseAttendList.add(baseAttend);
                tDays += daysDouble;
            }else{
                tDays += 1.0;
            }
        }
        baseAttendResult.setAttendList(baseAttendList);
        baseAttendResult.setDays(tDays);
        baseAttendResult.setItem(attendEvectionList.size());
        return baseAttendResult;
    }
    /*public AttendBase getChuChai(String userId, String beginDate, String endDate) {
        List<AttendWrappers> chuChaiList=new ArrayList<>();
        //获取总出差天数
        Double evecDayCount = 0.0;
        if(endDate.equals(DateFormat.getCurrentTime2())){
            endDate = DateFormat.getStrDate(new Date());
        }
        List<AttendEvection> attendEvectionList = attendEvectionMapper.selectAttendEvectionListByUserDd(userId, beginDate, endDate);
        if (attendEvectionList != null && attendEvectionList.size() > 0) {
            for (int i = 0; i < attendEvectionList.size(); i++) {
                AttendEvection attendEvection = attendEvectionList.get(i);
                //出差天数
                String evecDays = attendEvection.getEvecDays();
                Double evecDay = 0.0;
                if (evecDays != null && !evecDays.equals("")) {
                    evecDay = Double.valueOf(evecDays);
                } else {
                    evecDay = getDayByDate(attendEvection.getEvectionDate1(), attendEvection.getEvectionDate2()).doubleValue();
                }
                chuChaiList.add(setLiucheng(sdf1.format(attendEvection.getEvectionDate1()),sdf1.format(attendEvection.getEvectionDate2()),evecDay+""));
                evecDayCount = evecDayCount + evecDay;
            }
        }
        AttendBase attendBase=new AttendBase();
        attendBase.setChuChaiDouble(evecDayCount);
        attendBase.setChuChaiList(chuChaiList);
        attendBase.setChuchaixiangqing(attendEvectionList);
        return attendBase;
    }*/

    //获得两个时间日期之间的天数
    public Integer getDayByDate(Date beginDate, Date endDate) {
        Long day = (endDate.getTime() - beginDate.getTime()) / (24 * 60 * 60 * 1000);
        return day.intValue();
    }

    /**
     * 获取日期对应的星期
     *
     * @param date
     * @return
     */
    public String getWeekByData(String date) {
        Integer week = 0;
        String weekString = null;
        try {
            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date date1 = simpleDateFormat.parse(date);
            calendar.setTime(date1);
            int i = calendar.get(Calendar.DAY_OF_WEEK);
            if (i == 1) {
                week = 7;
            } else {
                week = i - 1;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        switch (week) {
            case 1:
                weekString = "星期一";
                break;
            case 2:
                weekString = "星期二";
                break;
            case 3:
                weekString = "星期三";
                break;
            case 4:
                weekString = "星期四";
                break;
            case 5:
                weekString = "星期五";
                break;
            case 6:
                weekString = "星期六";
                break;
            case 7:
                weekString = "星期日";
                break;
        }
        return weekString;
    }

    //获取未签
    public Map<String, List<AttendWrappers>> getWeiQian(AttendSet attendSet, String date) {
        List<AttendWrappers> weiQianDao = new ArrayList<>();
        List<AttendWrappers> weiQianTui = new ArrayList<>();
        Map<String, List<AttendWrappers>> weiQianMap = new HashMap<>();
        if (attendSet != null) {
            if (attendSet.getAtime1Setother().equals("1")) {
                //上班
                if (attendSet.getCommute1().equals("1")) {
                    AttendWrappers weiQian = new AttendWrappers();
                    weiQian.setDate(date);
                    weiQian.setTime(attendSet.getAtime1());
                    weiQian.setWeek(getWeekByData(date));
                    weiQian.setType("未签到");
                    weiQianDao.add(weiQian);
                }
                //下班
                else {
                    AttendWrappers weiTui = new AttendWrappers();
                    weiTui.setDate(date);
                    weiTui.setTime(attendSet.getAtime1());
                    weiTui.setWeek(getWeekByData(date));
                    weiTui.setType("未签退");
                    weiQianTui.add(weiTui);
                }
                if (attendSet.getAtime2Setother().equals("1")) {
                    //上班
                    if (attendSet.getCommute2().equals("1")) {
                        AttendWrappers weiQian = new AttendWrappers();
                        weiQian.setDate(date);
                        weiQian.setTime(attendSet.getAtime1());
                        weiQian.setWeek(getWeekByData(date));
                        weiQian.setType("未签到");
                        weiQianDao.add(weiQian);
                    }
                    //下班
                    else {
                        AttendWrappers weiTui = new AttendWrappers();
                        weiTui.setDate(date);
                        weiTui.setTime(attendSet.getAtime1());
                        weiTui.setWeek(getWeekByData(date));
                        weiTui.setType("未签退");
                        weiQianTui.add(weiTui);
                    }
                }

                if (attendSet.getAtime3Setother().equals("1")) {
                    //上班
                    if (attendSet.getCommute3().equals("1")) {
                        AttendWrappers weiQian = new AttendWrappers();
                        weiQian.setDate(date);
                        weiQian.setTime(attendSet.getAtime1());
                        weiQian.setWeek(getWeekByData(date));
                        weiQian.setType("未签到");
                        weiQianDao.add(weiQian);
                    }
                    //下班
                    else {
                        AttendWrappers weiTui = new AttendWrappers();
                        weiTui.setDate(date);
                        weiTui.setTime(attendSet.getAtime1());
                        weiTui.setWeek(getWeekByData(date));
                        weiTui.setType("未签退");
                        weiQianTui.add(weiTui);
                    }
                }

                if (attendSet.getAtime4Setother().equals("1")) {
                    //上班
                    if (attendSet.getCommute4().equals("1")) {
                        AttendWrappers weiQian = new AttendWrappers();
                        weiQian.setDate(date);
                        weiQian.setTime(attendSet.getAtime1());
                        weiQian.setWeek(getWeekByData(date));
                        weiQian.setType("未签到");
                        weiQianDao.add(weiQian);
                    }
                    //下班
                    else {
                        AttendWrappers weiTui = new AttendWrappers();
                        weiTui.setDate(date);
                        weiTui.setTime(attendSet.getAtime1());
                        weiTui.setWeek(getWeekByData(date));
                        weiTui.setType("未签退");
                        weiQianTui.add(weiTui);
                    }
                }

                if (attendSet.getAtime5Setother().equals("1")) {
                    //上班
                    if (attendSet.getCommute5().equals("1")) {
                        AttendWrappers weiQian = new AttendWrappers();
                        weiQian.setDate(date);
                        weiQian.setTime(attendSet.getAtime1());
                        weiQian.setWeek(getWeekByData(date));
                        weiQian.setType("未签到");
                        weiQianDao.add(weiQian);
                    }
                    //下班
                    else {
                        AttendWrappers weiTui = new AttendWrappers();
                        weiTui.setDate(date);
                        weiTui.setTime(attendSet.getAtime1());
                        weiTui.setWeek(getWeekByData(date));
                        weiTui.setType("未签退");
                        weiQianTui.add(weiTui);
                    }
                }
                if (attendSet.getAtime6Setother().equals("1")) {
                    //上班
                    if (attendSet.getCommute6().equals("1")) {
                        AttendWrappers weiQian = new AttendWrappers();
                        weiQian.setDate(date);
                        weiQian.setTime(attendSet.getAtime1());
                        weiQian.setWeek(getWeekByData(date));
                        weiQian.setType("未签到");
                        weiQianDao.add(weiQian);
                    }
                    //下班
                    else {
                        AttendWrappers weiTui = new AttendWrappers();
                        weiTui.setDate(date);
                        weiTui.setTime(attendSet.getAtime1());
                        weiTui.setWeek(getWeekByData(date));
                        weiTui.setType("未签退");
                        weiQianTui.add(weiTui);
                    }
                }

            }
        }
        weiQianMap.put("weiQianDao", weiQianDao);
        weiQianMap.put("weiQianTui", weiQianTui);
        return weiQianMap;
    }

    public AttendWrappers setAttendWrappers(String type, String date, String time) {
        AttendWrappers attendWrappers = new AttendWrappers();
        attendWrappers.setUserName(null);
        attendWrappers.setWeek(getWeekByData(date));
        if (time != null) {
            attendWrappers.setTime(time);
        }
        attendWrappers.setDate(date);
        attendWrappers.setType(type);
        return attendWrappers;
    }

    //导入
    public ToJson importAttend(MultipartFile file, HttpServletRequest request, HttpServletResponse response, HttpSession session) {
        ToJson json = new ToJson();
        // 成功次数
        Integer successCount = 0;
        try {
            //判读当前系统
            //读取配置文件
            ResourceBundle rb = ResourceBundle.getBundle("upload");
            String osName = System.getProperty("os.name");
            StringBuffer path = new StringBuffer();
            StringBuffer buffer = new StringBuffer();
            if (osName.toLowerCase().startsWith("win")) {
                //sb=sb.append(rb.getString("upload.win"));
                //判断路径是否是相对路径，如果是的话，加上运行的路径
                String uploadPath = rb.getString("upload.win");
                if (uploadPath.indexOf(":") == -1) {
                    //获取运行时的路径
                    String basePath = this.getClass().getClassLoader().getResource(".").getPath() + File.pathSeparator;
                    //获取截取后的路径
                    String str2 = "";
                    if (basePath.indexOf("/xoa") != -1) {
                        //获取字符串的长度
                        int length = basePath.length();
                        //返回指定字符在此字符串中第一次出现处的索引
                        int index = basePath.indexOf("/xoa");
                        //从指定位置开始到指定位置结束截取字符串
                        str2 = basePath.substring(0, index);
                    }
                    path = path.append(str2 + "/xoa");
                }
                path.append(uploadPath);
                buffer = buffer.append(rb.getString("upload.win"));
            } else {
                path = path.append(rb.getString("upload.linux"));
                buffer = buffer.append(rb.getString("upload.linux"));
            }
            // 判断是否为空文件
            if (file.isEmpty()) {
                json.setMsg("请上传文件！");
                json.setFlag(1);
                return json;
            } else {
                String fileName = file.getOriginalFilename();
                if (fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) {
                    String uuid = UUID.randomUUID().toString().replaceAll("-", "");
                    int pos = fileName.indexOf(".");
                    String extName = fileName.substring(pos);
                    String newFileName = uuid + extName;
                    File filedir = new File(path.toString());
                    if (!filedir.exists()) {
                        filedir.mkdirs();
                    }
                    File dest = new File(path.toString(), newFileName);
                    file.transferTo(dest);
                    // 将文件上传成功后进行读取文件
                    // 进行读取的路径
                    String readPath = path.append(System.getProperty("file.separator") + newFileName).toString();
                    InputStream in = new FileInputStream(readPath);
                    HSSFWorkbook excelObj = new HSSFWorkbook(in);
                    HSSFSheet sheetObj = excelObj.getSheetAt(0);
                    Row row = sheetObj.getRow(0);
                    int colNum = row.getPhysicalNumberOfCells();
                    int lastRowNum = sheetObj.getLastRowNum();
                    List<Attend> saveList = new ArrayList<Attend>();
                    Attend record = null;
                    for (int i = 1; i <= lastRowNum; i++) {
                        record = new Attend();
                        row = sheetObj.getRow(i);
                        if (row != null) {
                            for (int j = 0; j < colNum; j++) {
                                Cell cell = row.getCell(j);
                                if (cell != null) {
                                    switch (j) {
                                        case 0:
                                            //用户名
                                            Users users = usersMapper.findUsersByuserId(getCellValue(cell));
                                            Integer userid = users.getUid();
                                            if (userid != null) {
                                                record.setUid(userid);
                                            } else {
                                                json.setMsg("用户不存在");
                                                return json;
                                            }
                                            break;
                                        case 1:
                                            //登记日期
                                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                                            Date date = new Date();
                                            if (!(getCellValue(cell)).equals("") && getCellValue(cell) != null) {
                                                record.setDate(sdf.parse(getCellValue(cell)));
                                            } else {
                                                record.setDate(date);
                                            }
                                            break;
                                        case 2:
                                            //签到次数（类型）
                                            record.setType(String.valueOf(getCellValue(cell)));
                                            break;
                                        case 3:
                                            //签到时间
                                            if (!(getCellValue(cell)).equals("") && getCellValue(cell) != null) {
                                                record.setAtime(Integer.parseInt(getCellValue(cell)));
                                            } else {
                                                record.setAtime(Integer.parseInt(String.valueOf(System.currentTimeMillis() / 1000)));
                                            }
                                            break;
                                        case 4:
                                            //备注
                                            if (!(getCellValue(cell)).equals("") && getCellValue(cell) != null) {
                                                record.setRemark(String.valueOf(getCellValue(cell)));
                                            } else {
                                                record.setRemark(null);
                                            }
                                            break;
                                        case 5:
                                            //定位地点名称
                                            if (!(getCellValue(cell)).equals("") && getCellValue(cell) != null) {
                                                record.setAddress(String.valueOf(getCellValue(cell)));
                                            } else {
                                                record.setAddress(null);
                                            }
                                            break;
                                        case 6:
                                            //签到手机ID号
                                            if (!(getCellValue(cell)).equals("") && getCellValue(cell) != null) {
                                                record.setPhoneId(String.valueOf(getCellValue(cell)));
                                            } else {
                                                record.setPhoneId(null);
                                            }
                                            break;
                                        case 7:
                                            //设备型号
                                            if (!(getCellValue(cell)).equals("") && getCellValue(cell) != null) {
                                                record.setDevice(String.valueOf(getCellValue(cell)));
                                            } else {
                                                record.setDevice(null);
                                            }
                                            break;
                                    }
                                }
                            }
                        }
                        int count = attendMapper.insertSelective(record);
                        if (count > 0) {
                            successCount++;
                        }
                    }
                } else {
                    json.setMsg("file type error!");
                    json.setFlag(1);
                    return json;
                }
            }
            json.setTotleNum(successCount);
            json.setMsg("ok");
            json.setFlag(0);
        } catch (Exception e) {
            e.printStackTrace();
            json.setMsg(e.getMessage());
            json.setFlag(1);
        }
        return json;
    }


    private String getCellValue(Cell cell) {
        Object value = null;
        switch (cell.getCellType()) {
            case STRING:
                value = cell.getStringCellValue();
                break;
            case NUMERIC:
                value = (int) cell.getNumericCellValue();
                break;
            default:
                value = cell.getStringCellValue();
                break;
        }
        return String.valueOf(value);
    }

    private void paixu(List<AttendWrappers> list) {
        Collections.sort(list, new Comparator<AttendWrappers>() {
            @Override
            public int compare(AttendWrappers o1, AttendWrappers o2) {
                try {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    int flag = sdf.parse(o1.getDate()).compareTo(sdf.parse(o2.getDate()));
                    return flag;
                } catch (Exception e) {
                    System.out.println(e);
                }
                return 0;
            }
        });
    }
    //设置全局attendSet对象集   用Map接受可快速查询次对象是否存在，对象的id为map的键，值为对象的引用

    public AttendSetWrappers findAttendList3(Integer dutyType, Integer deptId,
                                             String beginDate, String endDate, Integer pageNo, Integer pageSize, Integer oneUid,
                                             HttpServletRequest req, Map<String, Object> mapE) {
        //findAttendList2();
        //考勤设置实体类集合
        Map<Integer, AttendSet> attendSetMap = new HashMap<>();
        //考勤规则实体类集合
        Map<String, AttendRule> attendRuleMap = new HashMap<>();
        List<AttendTJ> attendTJList = new ArrayList<>();
        //1、查询出符合条件的人员
        Map<String, Object> map = new HashMap<>();
        map.put("dutyType", dutyType);
        map.put("deptId", deptId);
        map.put("beginDate", beginDate);
        map.put("endDate", endDate);
        map.put("uid", oneUid);
        Integer total = userDutyMapper.getTotalByMap(map);
        Integer startNum = null;
        Integer endNum = null;
        if (pageNo != null && pageSize != null) {
            startNum = (pageNo - 1) * pageSize;
            endNum = pageSize;
        }
        map.put("startNum", startNum);
        map.put("endNum", endNum);
        //获取符合查询条件的记录
        //List<Integer> uids = userDutyMapper.getUserDutyListByMap(map);
        //List<List<UserDuty>> userDutyLists = getUserDutys(uids,map);
        Map<String, String> userAndDeptName = new HashMap<>();
        List<Object> userDutyLists = getUserDutyList(map);//获得多个人员的排班userDutyLists
        if (userDutyLists != null) {
            for (Object object : userDutyLists) {
                AttendTJ attendTJ = new AttendTJ();
                List queqinList = new ArrayList<>();
                List weiqiandaoList = new ArrayList<>();
                List shangbanList = new ArrayList<>();
                List xiabanList = new ArrayList<>();
                List weiqiantuiList = new ArrayList<>();
                List chidaoList = new ArrayList<>();
                List zaotuiList = new ArrayList<>();
                List yichangList = new ArrayList<>();
                List shebeiyichang = new ArrayList<>();
                List waiqinList = new ArrayList<>();
                List shijichuqinList = new ArrayList<>();
                List yingchuqinList = new ArrayList<>();
                Integer quanqin = 0;
                Integer uid = null;
                if (object instanceof ArrayList) {
                    List<UserDuty> userDutyList = (ArrayList<UserDuty>) object;
                    //当前用户uid
                    uid = userDutyList.get(0).getUid();
                    userAndDeptName = attendMapper.getUserNameAndDeptNameByUid(uid);
                    //获取当前用户的考勤规则。
                    Object deptid = userAndDeptName.get("deptid");
                    String deptIds = null;
                    if (deptid != null) {
                        if (deptid instanceof Integer) {
                            deptIds = deptid + "";
                        } else {
                            deptIds = (String) deptid;
                        }
                    }
                    AttendRule attendRule = attendRuleMap.get(deptIds);
                    if (attendRule == null) {
                        //防止重复数据
                        List<AttendRule> attendRules = attendRuleMapper.getAttendRuleByDept(Integer.parseInt(deptIds));
                        if (attendRules != null && attendRules.size() > 0) {
                            attendRule = attendRules.get(0);
                            attendRuleMap.put(deptIds, attendRule);
                        }
                    }
                    //获取每个用户的排班信息进行归类
                    String device = null;
                    for (UserDuty userDuty : userDutyList) {
                        boolean quan = true;//如果当天不是全勤则为false
                        //当前用户当前排班的考勤类型
                        Integer userDutyType = userDuty.getDutyType();
                        //先查询在attendSetMap中是否存在，如果存在省去查数据库步骤，提高效率。
                        AttendSet attendSet = attendSetMap.get(userDutyType);
                        if (attendSet == null) {
                            attendSet = attendSetMapper.selectAttendSetSid(userDutyType);
                            attendSetMap.put(userDutyType, attendSet);
                        }
                        //根据uid和日期查找用户的签到信息
                        List<Attend> attendList = attendMapper.getAttendListByUidAndDates(uid, beginDate, endDate);
                        //按日期分组
                        Map<String, Map<String, Attend>> groudAttendMap = groudAttendByDateType(attendList);
                        Map<String, Attend> attendMap = groudAttendMap.get(userDuty.getDutyDate());
                        //考虑当当前考勤类型不存在时，也就是被删除的时候，忽略
                        if (attendSet != null) {
                            setAttendsetOtherNull(attendSet);
                            yingchuqinList.add(userDuty);
                            if (attendMap != null) {
                                shijichuqinList.add(userDuty);
                                try {
                                    Class c = attendSet.getClass().forName("com.xoa.model.attend.AttendSet");
                                    c.newInstance();
                                    //上次手机签到型号
                                    for (int i = 1; i <= 6; i++) {
                                        Method methodget = c.getMethod("getAtime" + i + "Set");
                                        String getAtimeSet = (String) methodget.invoke(attendSet);
                                        if (getAtimeSet != null) {
                                            if (getAtimeSet.contains("|")) {
                                                String[] getAtimeSets = getAtimeSet.split("\\|");
                                                String kaiguan = getAtimeSets[0];
                                                String type = getAtimeSets[1];
                                                if (kaiguan.equals("1")) {
                                                    Attend attend = attendMap.get(String.valueOf(i));
                                                    Method methodGetAtime = c.getMethod("getAtime" + i);
                                                    String getAtime = (String) methodGetAtime.invoke(attendSet);
                                                    if (getAtime.length() < 10) {//兼容处理
                                                        getAtime = userDuty.getDutyDate() + " " + getAtime;
                                                    }
                                                    Method setAtimeSetother = c.getMethod("setAtime" + i + "Setother", new Class[]{String.class});
                                                    if (attend != null) {
                                                        String dbDevice = attend.getDevice();
                                                        if (dbDevice != null && !dbDevice.equals("")) {
                                                            if (device != null && !dbDevice.equals(device)) {
                                                                //设备异常
                                                                shebeiyichang.add(attend);
                                                            }
                                                            device = dbDevice;
                                                        }
                                                        //签到时间
                                                        Integer atime = attend.getAtime();//秒级时间戳
                                                        String atimeStr = DateFormat.getStrTime(atime);
                                                        attend.setaTime(atimeStr);
                                                        if (atimeStr != null) {
                                                            String[] aTimeArray = atimeStr.split(" ");
                                                            if (aTimeArray.length > 1) {
                                                                setAtimeSetother.invoke(attendSet, new Object[]{aTimeArray[1]});
                                                            }

                                                        }
                                                        //应签到时间
                                                        Integer yAtime = DateFormat.getNowDateTime(getAtime);
                                                        attend.setyTime(getAtime);
                                                        //下班
                                                        if (Integer.parseInt(type) == 2) {
                                                            //签到时间大于等于应签到时间即为准时
                                                            if (atime >= yAtime) {
                                                                xiabanList.add(attend);
                                                            } else {
                                                                //早退
                                                                //查看是否有旷工规则
                                                                Integer oneEarlyHour = null;
                                                                //attendRule.getOneEarlyHour();
                                                                if (oneEarlyHour != null && oneEarlyHour > 0) {
                                                                    oneEarlyHour = oneEarlyHour * 60;
                                                                    //如果签退的时间加上 早退规则依然小于下班时间，缺勤
                                                                    if (atime + oneEarlyHour < yAtime) {
                                                                        weiqiantuiList.add(userDuty);
                                                                    } else {
                                                                        zaotuiList.add(attend);
                                                                    }
                                                                } else {
                                                                    zaotuiList.add(attend);
                                                                }

                                                            }
                                                            //上班
                                                        } else {
                                                            if (atime <= yAtime) {
                                                                shangbanList.add(attend);
                                                            } else {
                                                                //迟到
                                                                //查看是否有旷工规则
                                                                Integer oneLateHour = null;
                                                                //Integer oneLateHour=attendRule.getOneLateHour();
                                                                if (oneLateHour != null && oneLateHour > 0) {
                                                                    oneLateHour = oneLateHour * 60;
                                                                    //如果签到时间大于应签到时间+迟到规则。缺勤
                                                                    if (atime > yAtime + oneLateHour) {
                                                                        weiqiandaoList.add(userDuty);
                                                                    } else {
                                                                        chidaoList.add(attend);
                                                                    }
                                                                } else {
                                                                    chidaoList.add(attend);
                                                                }
                                                            }
                                                        }
                                                    } else {
                                                        //无当前签到记录
                                                        quan = false;
                                                        if (Integer.parseInt(type) == 2) {
                                                            weiqiantuiList.add(getAtime);
                                                        } else {
                                                            weiqiandaoList.add(getAtime);
                                                        }
                                                        setAtimeSetother.invoke(attendSet, new Object[]{"0"});
                                                    }
                                                }
                                                //Method methodset = c.getMethod("setAtime" + i + "Setother", new Class[]{String.class});
                                                //methodset.invoke(attendSet, new Object[]{kaiguan});
                                            }
                                        }
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }


                                if (quan == true) {
                                    quanqin++;
                                }

                            } else {
                                //没有当天的签到信息,缺勤
                                queqinList.add(userDuty);
                                try {
                                    Class c = attendSet.getClass().forName("com.xoa.model.attend.AttendSet");
                                    c.newInstance();
                                    for (int i = 1; i <= 6; i++) {
                                        Method methodget = c.getMethod("getAtime" + i + "Set");
                                        String getAtimeSet = (String) methodget.invoke(attendSet);
                                        if (getAtimeSet != null) {
                                            if (getAtimeSet.contains("|")) {
                                                String[] getAtimeSets = getAtimeSet.split("\\|");
                                                String kaiguan = getAtimeSets[0];
                                                String type = getAtimeSets[1];
                                                if (kaiguan.equals("1")) {
                                                    Method methodGetAtime = c.getMethod("getAtime" + i);
                                                    String getAtime = (String) methodGetAtime.invoke(attendSet);
                                                    if (getAtime.length() < 10) {//兼容处理
                                                        getAtime = userDuty.getDutyDate() + " " + getAtime;
                                                    }
                                                    if (Integer.parseInt(type) == 1) {
                                                        weiqiandaoList.add(getAtime);
                                                    } else {
                                                        weiqiantuiList.add(getAtime);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            AttendSet attendSetCopy = new AttendSet();
                            BeanUtils.copyProperties(attendSet, attendSetCopy);
                            userDuty.setAttendSet(attendSetCopy);
                        } else {
                            //清除无意义的排班
                            //userDutyList.remove(userDuty);
                        }

                        //每个用户的排班循环层
                    }
                } else if (object instanceof Integer) {
                    uid = (Integer) object;
                }
                Map map1 = new HashMap();
                map1.put("uid", uid);
                map1.put("beginDate", beginDate);
                map1.put("endDate", endDate);
                map1.put("type", 7);
                //查找加班信息
                List<Attend> attendList = attendMapper.getAttendListByMap(map1);
                if (attendList != null) {
                    for (Attend attend0 : attendList) {
                        Integer atime = attend0.getAtime();
                        String atimeStr = DateFormat.getStrTime(atime);
                        attend0.setaTime(atimeStr);
                    }
                }
                attendTJ.setJiaban(attendList);
                //查找外勤
                map1.put("type", 0);
                //查看今天是否有外勤数据
                List<Attend> attendWList = attendMapper.getAttendListByMap(map1);
                if (attendWList != null) {
                    for (Attend attend0 : attendWList) {
                        Integer atime = attend0.getAtime();
                        String atimeStr = DateFormat.getStrTime(atime);
                        attend0.setaTime(atimeStr);
                        waiqinList.add(attend0);
                    }
                }


                String userId = userAndDeptName.get("userid");
                String userName = userAndDeptName.get("username");
                String deptName = userAndDeptName.get("deptname");
                attendTJ.setChidaoList(chidaoList);
                attendTJ.setQuanqin(quanqin);
                attendTJ.setQueqinList(queqinList);
                attendTJ.setShangbanList(shangbanList);
                attendTJ.setShebeiyichang(shebeiyichang);
                attendTJ.setWaiqinList(waiqinList);
                attendTJ.setWeiqiandaoList(weiqiandaoList);
                attendTJ.setWeiqiantuiList(weiqiantuiList);
                attendTJ.setXiabanList(xiabanList);
                attendTJ.setUid(uid);
                attendTJ.setUserId(userId);
                attendTJ.setUserName(userName);
                attendTJ.setDeptName(deptName);
                attendTJ.setYingchuqin(yingchuqinList);
                attendTJ.setShijichuqin(shijichuqinList);
                attendTJ.setZaotuiList(zaotuiList);
                attendTJList.add(attendTJ);
                try {
                    //获取请假
                    BaseAttend qingjia = getQingJia(userId, beginDate, endDate);
                    attendTJ.setQingjia(qingjia);
                    //获取外出
                    BaseAttend waichu = getWaiChu(userId, beginDate, endDate);
                    attendTJ.setWaichu(waichu);
                /*BaseAttend jiaban=getJiaBan(userId,beginDate,endDate);
                attendTJ.setJiaban(jiaban);*/
                    //获取出差
                    BaseAttend chuchai = getChuChai(userId, beginDate, endDate);
                    attendTJ.setChuchai(chuchai);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                //获取
                //用户循环层
            }
        }
        //导出
        try {
            String exType = (String) mapE.get("exType");
            HttpServletResponse response = (HttpServletResponse) mapE.get("response");
            if (exType != null) {
                if (exType.equals("1")) {
                    exportExcel(response, attendTJList, exType);
                } else if (exType.equals("2")) {
                    exportExcel(response, attendTJList, exType);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        AttendSetWrappers wrappers = new AttendSetWrappers();
        wrappers.setFlag(true);
        wrappers.setStatus(true);
        wrappers.setData(attendTJList);
        wrappers.setTotleNum(total);
        if (attendTJList.size() > 0) {
            wrappers.setMsg("查询成功");
        } else {
            wrappers.setMsg("查询无数据");
        }
        return wrappers;

    }

    /**
     * @创建作者:李然 Lr
     * @方法描述：用反射至0
     * @创建时间：12:02 2019/3/14
     **/
    public void setAttendsetOtherNull(AttendSet attendSet) {
        try {
            for (int i = 1; i <= 6; i++) {
                Class c = attendSet.getClass().forName("com.xoa.model.attend.AttendSet");
                Method setAtimeSetother = c.getMethod("setAtime" + i + "Setother", new Class[]{String.class});
                setAtimeSetother.invoke(attendSet, new Object[]{"0"});
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //固定签到信息按 日期和类型分组
    public Map<String, Map<String, Attend>> groudAttendByDateType(List<Attend> attendList) {
        //用于格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Map<String, Map<String, Attend>> dataAttendMap = new HashMap<>();
        //按照日期进行分组
        if (attendList != null) {
            for (Attend attend : attendList) {
                String attendTime = DateFormat.getDatestr(attend.getDate());
                Map<String, Attend> attendMap = dataAttendMap.get(attendTime);
                if (attendMap == null) {
                    attendMap = new HashMap<>();
                }
                attendMap.put(attend.getType(), attend);
                dataAttendMap.put(attendTime, attendMap);
            }
        }
        return dataAttendMap;
    }

    //自由签到签到信息按日期分组
    public Map<String, List<Attend>> groudAttendByDate(List<Attend> attendList) {
        //用于格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Map<String, List<Attend>> dataAttendMap = new HashMap<>();
        //按照日期进行分组
        if (attendList != null) {
            for (Attend attend : attendList) {
                String attendTime = DateFormat.getDatestr(attend.getDate());
                List<Attend> list = dataAttendMap.get(attendTime);
                list = list == null ? new ArrayList<>() : list;
                list.add(attend);
                dataAttendMap.put(attendTime, list);
            }
        }
        return dataAttendMap;
    }

    /**
     * @创建作者:李然 Lr
     * @方法描述：通用导出
     * @创建时间：12:04 2019/3/14
     **/
    public void exportExcel(HttpServletResponse response, List<AttendTJ> attendTJList, String type) {
        String kaoqinTableName = "";
        if (type.equals("1")) {
            kaoqinTableName = "考勤统计表";
        } else {
            kaoqinTableName = "个人考勤统计表";
        }
        HSSFWorkbook wb = new HSSFWorkbook();
        // 第二步，在webbook中添加一个sheet,对应Excel文件中的sheet
        HSSFSheet sheet = wb.createSheet(kaoqinTableName);
        // 第四步，创建单元格，并设置值表头 设置表头居中
        HSSFFont font = wb.createFont();
        font.setFontHeightInPoints((short) 11); // 字体高度
        font.setColor(HSSFFont.COLOR_NORMAL); // 字体颜色
        font.setFontName("宋体"); // 字体
        font.setBold(true);
        font.setItalic(false); // 是否使用斜体
        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER);//创建居中格式
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setFont(font);
        style.setBorderBottom(BorderStyle.THIN); //下边框
        style.setBorderLeft(BorderStyle.THIN);//左边框
        style.setBorderTop(BorderStyle.THIN);//上边框
        style.setBorderRight(BorderStyle.THIN);//右边框
        HSSFFont font1 = wb.createFont();
        font1.setFontHeightInPoints((short) 11); // 字体高度
        font1.setColor(HSSFFont.COLOR_NORMAL); // 字体颜色
        font1.setFontName("宋体"); // 字体
        font1.setBold(true); // 宽度
        font1.setItalic(false); // 是否使用斜体
        HSSFCellStyle style1 = wb.createCellStyle();
        style1.setVerticalAlignment(VerticalAlignment.CENTER);
        style1.setAlignment(HorizontalAlignment.CENTER); // 创建一个居中格式
        style1.setFont(font1);
        style1.setWrapText(true);
        style1.setBorderBottom(BorderStyle.THIN); //下边框
        style1.setBorderLeft(BorderStyle.THIN);//左边框
        style1.setBorderTop(BorderStyle.THIN);//上边框
        style1.setBorderRight(BorderStyle.THIN);//右边框
        HSSFFont font0 = wb.createFont();
        font0.setFontName("方正小标宋简体");//设置字体名称
        font0.setFontHeightInPoints((short) 20);//设置字号
        font0.setColor(HSSFFont.COLOR_NORMAL);//设置字体颜色
        font0.setUnderline(HSSFFontFormatting.U_SINGLE);//设置下划线
        HSSFCellStyle style0 = wb.createCellStyle();
        style0.setVerticalAlignment(VerticalAlignment.CENTER);
        style0.setAlignment(HorizontalAlignment.CENTER); // 创建一个居中格式
        style0.setFont(font0);
        String kaoqinxls = "";
        if (type.equals("1")) {
            kaoqinxls = "考勤统计";
            sheet.setDefaultRowHeight((short) (300 * 1));
            //sheet.setColumnWidth(0, 256*12); //设置某一列宽度
            sheet.setColumnWidth(0, 256 * 15); //设置某一列宽度
            sheet.setColumnWidth(1, 256 * 15); //设置某一列宽度
            int rowNum = 1;
            HSSFRow rowTitle = sheet.createRow(0);
            rowTitle.setHeight((short) (25 * 20));
            String[] titleArray = {"姓名", "部门", "应出勤", "实际出勤", "全勤", "上班准时", "下班准时", "迟到", "早退", "未签到", "未签退", "未出勤", "设备异常", "请假", "外出", "加班", "出差"};
            for (int j = 0; j < titleArray.length; j++) {
                HSSFCell hssfCell = rowTitle.createCell(j);
                hssfCell.setCellValue(titleArray[j]);
                hssfCell.setCellStyle(style);
            }

            String[] bodyArray = {"UserName", "DeptName", "Yingchuqin", "Shijichuqin", "Quanqin", "ShangbanList", "XiabanList", "ChidaoList",
                    "ZaotuiList", "WeiqiandaoList", "WeiqiantuiList", "QueqinList", "Shebeiyichang", "Qingjia", "Waichu", "Jiaban", "Chuchai"};
            for (int i = 0; i < attendTJList.size(); i++) {
                HSSFRow row = sheet.createRow(rowNum);
                AttendTJ attendTJ = attendTJList.get(i);
                try {
                    Class c = attendTJ.getClass().forName("com.xoa.service.attend.wrapper.AttendTJ");
                    c.newInstance();
                    for (int j = 0; j < titleArray.length; j++) {
                        Method methodget = c.getMethod("get" + bodyArray[j]);
                        Object getValue = methodget.invoke(attendTJ);
                        HSSFCell cell = row.createCell(j);
                        cell.setCellStyle(style1);
                        if (getValue != null) {
                            if (getValue instanceof String) {
                                cell.setCellValue((String) getValue);
                            } else if (getValue instanceof Integer) {
                                cell.setCellValue(((Integer) getValue));
                            } else if (getValue instanceof BaseAttend) {
                                cell.setCellValue(((BaseAttend) getValue).getDays());
                            } else {
                                cell.setCellValue(((List) getValue).size());
                            }
                        } else {
                            cell.setCellValue("0");
                        }

                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                rowNum++;
            }
        } else if (type.equals("2")) {
            kaoqinxls = "个人考勤统计";
            kaoqinTableName = "个人考勤统计表";
            sheet.setDefaultRowHeight((short) (300 * 2));
            //sheet.setColumnWidth(0, 256*12); //设置某一列宽度
            sheet.setColumnWidth(0, 256 * 15); //设置某一列宽度
            sheet.setColumnWidth(1, 256 * 15); //设置某一列宽度
            sheet.setColumnWidth(2, 256 * 21); //设置某一列宽度
            sheet.setColumnWidth(3, 256 * 21); //设置某一列宽度
            sheet.setColumnWidth(4, 256 * 21); //设置某一列宽度
            sheet.setColumnWidth(5, 256 * 21); //设置某一列宽度
            sheet.setColumnWidth(6, 256 * 21); //设置某一列宽度
            sheet.setColumnWidth(7, 256 * 21); //设置某一列宽度
            int rowName = 3;
            HSSFRow rowTitle = sheet.createRow(2);
            String[] titleArray = {"日期", "考勤类型", "签到1", "签到2", "签到3", "签到4", "签到5", "签到6"};
            for (int j = 0; j < titleArray.length; j++) {
                HSSFCell hssfCell = rowTitle.createCell(j);
                hssfCell.setCellValue(titleArray[j]);
                hssfCell.setCellStyle(style);
            }
            AttendTJ attendTJ = attendTJList.get(0);
            HSSFRow hssfRow0 = sheet.createRow(0);
            HSSFRow hssfRow1 = sheet.createRow(1);
            HSSFCell hssfCell0 = hssfRow0.createCell(0);
            HSSFCell hssfCell1 = hssfRow1.createCell(0);
            hssfCell0.setCellValue("用户：" + attendTJ.getUserName());
            hssfCell1.setCellValue("部门：" + attendTJ.getDeptName());
            hssfCell0.setCellStyle(style0);
            hssfCell1.setCellStyle(style0);
            CellRangeAddress regionRow0 = new CellRangeAddress(0, 0, 0, 1);
            CellRangeAddress regionRow1 = new CellRangeAddress(1, 1, 0, 1);
            sheet.addMergedRegion(regionRow0);
            sheet.addMergedRegion(regionRow1);
            List<UserDuty> userDutyList = attendTJ.getYingchuqin();
            for (UserDuty userDuty : userDutyList) {
                HSSFRow row = sheet.createRow(rowName);
                HSSFCell cell0 = row.createCell(0);
                cell0.setCellValue(userDuty.getDutyDate());
                cell0.setCellStyle(style1);
                AttendSet attendSet = userDuty.getAttendSet();
                HSSFCell cell1 = row.createCell(1);
                cell1.setCellValue(attendSet.getTitle());
                cell1.setCellStyle(style1);
                try {
                    Class c = attendSet.getClass().forName("com.xoa.model.attend.AttendSet");
                    c.newInstance();
                    for (int i = 1; i <= 6; i++) {
                        Method methodget = c.getMethod("getAtime" + i + "Set");
                        String getAtimeSet = (String) methodget.invoke(attendSet);
                        String value = "未开启";
                        if (getAtimeSet != null) {
                            String[] getAtimeSets = getAtimeSet.split("\\|");
                            String kaiguan = getAtimeSets[0];
                            if (kaiguan.equals("1")) {
                                Method methodGetAtime = c.getMethod("getAtime" + i);
                                String getAtime = (String) methodGetAtime.invoke(attendSet);
                                getAtime = "(" + getAtime + ")";
                                Method methodGetAtimeOther = c.getMethod("getAtime" + i + "Setother");
                                String getAtimeOther = (String) methodGetAtimeOther.invoke(attendSet);
                                if (getAtimeOther.equals("0")) {
                                    getAtimeOther = "未登记";
                                }
                                value = getAtime + getAtimeOther;
                            }
                        }
                        HSSFCell cell = row.createCell(i + 1);
                        cell.setCellValue(value);
                        cell.setCellStyle(style1);
                    }


                } catch (Exception e) {
                    e.printStackTrace();
                }
                rowName++;
            }
        }

        // 获取当前时间
        try {
            Calendar c = Calendar.getInstance();
            String time = "" + c.get(Calendar.YEAR) + (c.get(Calendar.MONTH) + 1)
                    + c.get(Calendar.DAY_OF_MONTH) + c.get(Calendar.HOUR_OF_DAY)
                    + c.get(Calendar.MINUTE);
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append(kaoqinxls).append(time.toString()).append(".xls");
            String fileName = stringBuffer.toString();
            response.setHeader("Content-disposition", "attachment;filename="
                    + URLEncoder.encode(fileName, "UTF-8"));
            response.setContentType("application/msexcel;charset=UTF-8");
            OutputStream out = response.getOutputStream();
            wb.write(out);
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * @创建作者:李然 Lr
     * @方法描述：手机端当天全体考勤
     * @创建时间：16:19 2019/3/21
     **/
    public BaseWrapper findListAll(String date) {
        AttendSetWrappers wrappers = new AttendSetWrappers();
        Attend shangban = new Attend();
        Attend xiaban = new Attend();
        Attend chidao = new Attend();
        Attend zaotui = new Attend();
        Attend weiqiandao = new Attend();
        Attend weiqiantui = new Attend();
        Attend waiqin = new Attend();
        Attend qingjia = new Attend();
        Attend chuchai = new Attend();
        Attend waichu = new Attend();
        Attend jiaban = new Attend();
        Attend zhiban = new Attend();
        List<BaseSupplement> shangbanList = new ArrayList<>();
        List<BaseSupplement> xiabanList = new ArrayList<>();
        List<BaseSupplement> chidaoList = new ArrayList<>();
        List<BaseSupplement> zaotuiList = new ArrayList<>();
        List<BaseSupplement> weiqiandaoList = new ArrayList<>();
        List<BaseSupplement> weiqiantuiList = new ArrayList<>();
        List<BaseSupplement> waiqinList = new ArrayList<>();
        List<BaseSupplement> qingjiaList = new ArrayList<>();
        List<BaseSupplement> chuchaiList = new ArrayList<>();
        List<BaseSupplement> waichuList = new ArrayList<>();
        List<BaseSupplement> jiabanList = new ArrayList<>();
        List<BaseSupplement> zhibanList = new ArrayList<>();
        Integer userAll = 0;
        Integer userSize = 0;
        Map<Integer, AttendSet> attendSetMap = new HashMap<>();
        //1、查询出符合条件的人员
        Map<String, Object> map = new HashMap<>();
        map.put("beginDate", date);
        map.put("endDate", date);
        try {
            //所有符合条件的用户
            List<Integer> uids = attendMapper.getUidAll();
//            if (uids != null) {
//                userAll = uids.size();
//            }
            List<List<UserDuty>> userDutyLists = getUserDutys(uids, map);//获得多个人员的排班userDutyLists
            if (userDutyLists != null) {
                userAll = userDutyLists.size();
                for (List<UserDuty> userDutyList : userDutyLists) {
                    Integer quanqin = 0;
                    //当前用户userDutyList应出勤天数
                    //当前用户uid
                    Integer uid = userDutyList.get(0).getUid();
                    Map<String, String> userAndDeptName = attendMapper.getUserNameAndDeptNameByUid(uid);
                    String userId = userAndDeptName.get("userid");
                    String userName = userAndDeptName.get("username");
                    String deptName = userAndDeptName.get("deptname");
                    //根据uid和日期查找用户的签到信息
                    List<Attend> attendList = attendMapper.getAttendListByUidAndDates(uid, date, date);
                    //按日期分组
                    Map<String, Map<String, Attend>> groudAttendMap = groudAttendByDateType(attendList);
                    //获取每个用户的排班信息进行归类
                    String device = null;
                    for (UserDuty userDuty : userDutyList) {
                        boolean quan = true;//如果当天不是全勤则为false
                        //当前用户当前排班的考勤类型
                        Integer userDutyType = userDuty.getDutyType();
                        //先查询在attendSetMap中是否存在，如果存在省去查数据库步骤，提高效率。
                        AttendSet attendSet = attendSetMap.get(userDutyType);
                        if (attendSet == null) {
                            attendSet = attendSetMapper.selectAttendSetSid(userDutyType);
                            attendSetMap.put(userDutyType, attendSet);
                        }
                        Map<String, Attend> attendMap = groudAttendMap.get(userDuty.getDutyDate());
                        //查看今天是否有外勤数据
                        if (attendMap != null) {
                            Attend attend0 = attendMap.get("0");
                            //当天存在签到
                            if (attend0 != null) {
                                Integer atime = attend0.getAtime();
                                String atimeStr = DateFormat.getStrTime(atime);
                                String str = "签到时间：" + atimeStr + "(" + attend0.getAddress() + ")";
                                BaseSupplement waiqinB = new BaseSupplement();
                                waiqinB.setStr(str);
                                waiqinB.setUid(uid);
                                waiqinB.setName(userName);
                                waiqinB.setDept(deptName);
                                waiqinList.add(waiqinB);
                            }
                        }
                        //考虑当当前考勤类型不存在时，也就是被删除的时候，忽略
                        if (attendSet != null) {
                            if (attendMap != null) {
                                userSize++;
                                try {
                                    Class c = attendSet.getClass().forName("com.xoa.model.attend.AttendSet");
                                    c.newInstance();
                                    for (int i = 1; i <= 6; i++) {
                                        Method methodget = c.getMethod("getAtime" + i + "Set");
                                        String getAtimeSet = (String) methodget.invoke(attendSet);
                                        if (getAtimeSet != null) {
                                            if (getAtimeSet.contains("|")) {
                                                String[] getAtimeSets = getAtimeSet.split("\\|");
                                                String kaiguan = getAtimeSets[0];
                                                String type = getAtimeSets[1];
                                                if (kaiguan.equals("1")) {
                                                    Attend attend = attendMap.get(String.valueOf(i));
                                                    Method methodGetAtime = c.getMethod("getAtime" + i);
                                                    String getAtime = (String) methodGetAtime.invoke(attendSet);
                                                    if (getAtime.length() < 10) {//兼容处理
                                                        getAtime = userDuty.getDutyDate() + " " + getAtime;
                                                    }
                                                    Method setAtimeSetother = c.getMethod("setAtime" + i + "Setother", new Class[]{String.class});
                                                    BaseSupplement dakaB = new BaseSupplement();
                                                    dakaB.setUid(uid);
                                                    dakaB.setName(userName);
                                                    dakaB.setDept(deptName);
                                                    if (attend != null) {
                                                        /*String dbDevice=attend.getDevice();
                                                        if(dbDevice!=null&&!dbDevice.equals("")){
                                                            if(device!=null&&!dbDevice.equals(device)){
                                                                //设备异常
                                                                shebeiyichang.add(attend);
                                                            }
                                                            device=dbDevice;
                                                        }*/
                                                        //签到时间
                                                        Integer atime = attend.getAtime();//秒级时间戳
                                                        String atimeStr = DateFormat.getStrTime(atime);
                                                        attend.setaTime(atimeStr);
                                                        if (atimeStr != null) {
                                                            String[] aTimeArray = atimeStr.split(" ");
                                                            if (aTimeArray.length > 1) {
                                                                setAtimeSetother.invoke(attendSet, new Object[]{aTimeArray[1]});
                                                            }

                                                        }
                                                        //应签到时间
                                                        Integer yAtime = DateFormat.getNowDateTime(getAtime);
                                                        attend.setyTime(getAtime);
                                                        dakaB.setStr("签到时间：" + atimeStr + "，(" + "应签到时间：" + getAtime + ")");
                                                        //下班
                                                        if (Integer.parseInt(type) == 2) {
                                                            //签到时间大于等于应签到时间即为准时
                                                            if (atime >= yAtime) {
                                                                xiabanList.add(dakaB);
                                                            } else {
                                                                zaotuiList.add(dakaB);
                                                            }
                                                            //上班
                                                        } else {
                                                            if (atime <= yAtime) {
                                                                shangbanList.add(dakaB);
                                                            } else {
                                                                chidaoList.add(dakaB);
                                                            }
                                                        }
                                                    } else {
                                                        //无当前签到记录
                                                        quan = false;
                                                        String str = "未签到(应签到时间" + getAtime + ")";
                                                        dakaB.setStr(str);
                                                        if (Integer.parseInt(type) == 2) {
                                                            weiqiantuiList.add(dakaB);
                                                        } else {
                                                            weiqiandaoList.add(dakaB);
                                                        }
                                                        setAtimeSetother.invoke(attendSet, new Object[]{"0"});
                                                    }
                                                }
                                                //Method methodset = c.getMethod("setAtime" + i + "Setother", new Class[]{String.class});
                                                //methodset.invoke(attendSet, new Object[]{kaiguan});
                                            }
                                        }
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }


                                if (quan == true) {
                                    quanqin++;
                                }

                            } else {
                                //没有当天的签到信息,缺勤
                                try {
                                    Class c = attendSet.getClass().forName("com.xoa.model.attend.AttendSet");
                                    c.newInstance();
                                    for (int i = 1; i <= 6; i++) {
                                        Method methodget = c.getMethod("getAtime" + i + "Set");
                                        String getAtimeSet = (String) methodget.invoke(attendSet);
                                        if (getAtimeSet != null) {
                                            if (getAtimeSet.contains("|")) {
                                                String[] getAtimeSets = getAtimeSet.split("\\|");
                                                String kaiguan = getAtimeSets[0];
                                                String type = getAtimeSets[1];
                                                if (kaiguan.equals("1")) {
                                                    Method methodGetAtime = c.getMethod("getAtime" + i);
                                                    String getAtime = (String) methodGetAtime.invoke(attendSet);
                                                    if (getAtime.length() < 10) {//兼容处理
                                                        getAtime = userDuty.getDutyDate() + " " + getAtime;
                                                    }
                                                    BaseSupplement dakaB = new BaseSupplement();
                                                    dakaB.setUid(uid);
                                                    dakaB.setName(userName);
                                                    dakaB.setDept(deptName);
                                                    String str = "未签到(应签到时间" + getAtime + ")";
                                                    dakaB.setStr(str);
                                                    if (Integer.parseInt(type) == 1) {
                                                        weiqiandaoList.add(dakaB);
                                                    } else {
                                                        weiqiantuiList.add(dakaB);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                /*queqinList.add(userDuty);*/
                            }
                        } else {
                            //清除无意义的排班
                            //userDutyList.remove(userDuty);
                        }

                        //每个用户的排班循环层
                    }
                    //用户循环层
                }
            }
            //加班，值班，独立于排班之外
            if (uids != null && uids.size() > 0) {
                List<Attend> attends = attendMapper.getJiaBanZhiBanListByUidsAndDate(uids, date);
                if (attends != null && attends.size() > 0) {
                    for (Attend attend : attends) {
                        BaseSupplement dakaB = new BaseSupplement();
                        dakaB.setUid(attend.getUid());
                        dakaB.setName(attend.getUserName());
                        dakaB.setDept(attend.getDepName());
                        String atimeStr = DateFormat.getStrTime(attend.getAtime());
                        String str = "签到时间：" + atimeStr;
                        dakaB.setStr(str);
                        if (attend.getType().equals("7")) {
                            jiabanList.add(dakaB);
                        } else if (attend.getType().equals("9")) {
                            zhibanList.add(dakaB);
                        }
                    }
                }
            }
            String endDate = date;
            if (date.length() < 11) {
                endDate = date + " 59:59:59";
            }
            Map mapAtt = new HashMap();
            mapAtt.put("date", date);
            mapAtt.put("endDate", endDate);
            mapAtt.put("uids", uids);
            //查询请假
            List<AttendLeave> attendLeaveList = attendLeaveMapper.getAttendLeaveByDateAndUids(mapAtt);
            if (attendLeaveList != null && attendLeaveList.size() > 0) {
                for (AttendLeave attendLeave : attendLeaveList) {
                    BaseSupplement baseSupplement = new BaseSupplement();
                    baseSupplement.setUid(attendLeave.getUid());
                    baseSupplement.setName(attendLeave.getUserName());
                    baseSupplement.setAvatar(attendLeave.getAvatar());
                    baseSupplement.setDept(attendLeave.getDeptName());
                    baseSupplement.setStr(DateFormat.getStrDate(attendLeave.getLeaveDate1()) + "至" + DateFormat.getStrDate(attendLeave.getLeaveDate2()));
                    baseSupplement.setContent("原因:" + attendLeave.getLeaveType());
                    baseSupplement.setFlag(attendLeave.getLeaveType2());
                    qingjiaList.add(baseSupplement);
                }
            }
            //查询出差
            List<AttendEvection> AttendEvectionList = attendEvectionMapper.getAttendLeaveByDateAndUids(mapAtt);
            if (AttendEvectionList != null && AttendEvectionList.size() > 0) {
                for (AttendEvection attendEvection : AttendEvectionList) {
                    BaseSupplement baseSupplement = new BaseSupplement();
                    baseSupplement.setUid(attendEvection.getUid());
                    baseSupplement.setName(attendEvection.getUserName());
                    baseSupplement.setAvatar(attendEvection.getAvatar());
                    baseSupplement.setDept(attendEvection.getDeptName());
                    baseSupplement.setStr(DateFormat.getStrDate(attendEvection.getEvectionDate1()) + "至" + DateFormat.getStrDate(attendEvection.getEvectionDate2()));
                    baseSupplement.setContent("原因:" + attendEvection.getReason());
                    chuchaiList.add(baseSupplement);
                }
            }
            //查询外出
            List<AttendOut> AttendOutList = attendOutMapper.getAttendLeaveByDateAndUids(mapAtt);
            if (AttendOutList != null && AttendOutList.size() > 0) {
                for (AttendOut attendOut : AttendOutList) {
                    BaseSupplement baseSupplement = new BaseSupplement();
                    baseSupplement.setUid(attendOut.getUid());
                    baseSupplement.setName(attendOut.getUserName());
                    baseSupplement.setAvatar(attendOut.getAvatar());
                    baseSupplement.setDept(attendOut.getDeptName());
                    baseSupplement.setStr(attendOut.getOutTime1() + "至" + attendOut.getOutTime2());
                    baseSupplement.setContent("原因:" + attendOut.getReason());
                    waichuList.add(baseSupplement);
                }
            }
        } catch (Exception e) {
            wrappers.setMsg("出现错误，请联系开发者");
        }
        shangban.setSname("上班正常");
        shangban.setType("次");
        shangban.setBaseSupplements(shangbanList);
        if (shangbanList.size() > 0) {
            shangban.setNum(shangbanList.size() + "次");
            shangban.setState(numberOne);
        } else {
            shangban.setState(numberZero);
            shangban.setNum(numberZero);
        }
        xiaban.setSname("下班正常");
        xiaban.setType("次");
        xiaban.setBaseSupplements(xiabanList);
        if (xiabanList.size() > 0) {
            xiaban.setNum(xiabanList.size() + "次");
            xiaban.setState(numberOne);
        } else {
            xiaban.setState(numberZero);
            xiaban.setNum(numberZero);
        }
        weiqiandao.setSname("未签到");
        weiqiandao.setType("次");
        weiqiandao.setBaseSupplements(weiqiandaoList);
        if (weiqiandaoList.size() > 0) {
            weiqiandao.setNum(weiqiandaoList.size() + "次");
            weiqiandao.setState(numberOne);
        } else {
            weiqiandao.setState(numberZero);
            weiqiandao.setNum(numberZero);
        }
        weiqiantui.setSname("未签退");
        weiqiantui.setType("次");
        weiqiantui.setBaseSupplements(weiqiantuiList);
        if (weiqiantuiList.size() > 0) {
            weiqiantui.setNum(weiqiantuiList.size() + "次");
            weiqiantui.setState(numberOne);
        } else {
            weiqiantui.setState(numberZero);
            weiqiantui.setNum(numberZero);
        }
        chidao.setSname("迟到");
        chidao.setType("次");
        chidao.setBaseSupplements(chidaoList);
        if (chidaoList.size() > 0) {
            chidao.setNum(chidaoList.size() + "次");
            chidao.setState(numberOne);
        } else {
            chidao.setState(numberZero);
            chidao.setNum(numberZero);
        }
        zaotui.setSname("早退");
        zaotui.setType("次");
        zaotui.setBaseSupplements(zaotuiList);
        if (zaotuiList.size() > 0) {
            zaotui.setNum(zaotuiList.size() + "次");
            zaotui.setState(numberOne);
        } else {
            zaotui.setState(numberZero);
            zaotui.setNum(numberZero);
        }
        waiqin.setSname("外勤");
        waiqin.setType("次");
        waiqin.setBaseSupplements(waiqinList);
        if (waiqinList.size() > 0) {
            waiqin.setNum(waiqinList.size() + "次");
            waiqin.setState(numberOne);
        } else {
            waiqin.setState(numberZero);
            waiqin.setNum(numberZero);
        }
        chuchai.setSname("出差");
        chuchai.setType("次");
        chuchai.setBaseSupplements(chuchaiList);
        if (chuchaiList.size() > 0) {
            chuchai.setNum(chuchaiList.size() + "次");
            chuchai.setState(numberOne);
        } else {
            chuchai.setState(numberZero);
            chuchai.setNum(numberZero);
        }
        waichu.setSname("外出");
        waichu.setType("次");
        waichu.setBaseSupplements(waichuList);
        if (waichuList.size() > 0) {
            waichu.setNum(waichuList.size() + "次");
            waichu.setState(numberOne);
        } else {
            waichu.setState(numberZero);
            waichu.setNum(numberZero);
        }
        qingjia.setSname("请假");
        qingjia.setType("次");
        qingjia.setBaseSupplements(qingjiaList);
        if (qingjiaList.size() > 0) {
            qingjia.setNum(qingjiaList.size() + "次");
            qingjia.setState(numberOne);
        } else {
            qingjia.setState(numberZero);
            qingjia.setNum(numberZero);
        }
        jiaban.setSname("加班");
        jiaban.setType("次");
        jiaban.setBaseSupplements(jiabanList);
        if (jiabanList.size() > 0) {
            jiaban.setNum(jiabanList.size() + "次");
            jiaban.setState(numberOne);
        } else {
            jiaban.setState(numberZero);
            jiaban.setNum(numberZero);
        }
        zhiban.setSname("值班");
        zhiban.setType("次");
        zhiban.setBaseSupplements(zhibanList);
        if (zhibanList.size() > 0) {
            zhiban.setNum(zhibanList.size() + "次");
            zhiban.setState(numberOne);
        } else {
            zhiban.setState(numberZero);
            zhiban.setNum(numberZero);
        }


        List<Attend> attends = new ArrayList<>();
        attends.add(shangban);
        attends.add(xiaban);
        attends.add(chidao);
        attends.add(zaotui);
        attends.add(weiqiandao);
        attends.add(weiqiantui);
        attends.add(waiqin);
        attends.add(chuchai);
        attends.add(waichu);
        attends.add(qingjia);
        attends.add(zhiban);
        attends.add(jiaban);
        Attend attend = new Attend();
        attend.setUserAll(userAll);
        attend.setUserSize(userSize);
        attend.setList(attends);
        wrappers.setFlag(true);
        wrappers.setStatus(true);
        wrappers.setData(attend);
        return wrappers;
    }

    public List<List<UserDuty>> getUserDutys(List<Integer> uids, Map map) {
        if (uids != null && uids.size() > 0) {
            List<UserDuty> userDutyList = userDutyMapper.getUserDutyListByUidList(uids, map);
            Set<Integer> uidSet = new HashSet<>(uids);
            if (userDutyList != null && userDutyList.size() > 0) {
                for (int i = 0; i < userDutyList.size(); i++) {
                    uidSet.add(userDutyList.get(i).getUid());
                }
            }
            //定义分组后的list
            List<List<UserDuty>> userDutys = new ArrayList<>();
            //去重完毕
            List<Integer> uidList = new ArrayList<>(uidSet);
            if (uidList != null && uidList.size() > 0) {
                //按照uid进行分组list
                for (int i = 0; i < uidList.size(); i++) {
                    Integer uid = uidList.get(i);
                    List<UserDuty> userDuties = new ArrayList<>();
                    for (int j = 0; j < userDutyList.size(); j++) {
                        Integer uid2 = userDutyList.get(j).getUid();
                        if (uid2.equals(uid)) {
                            userDuties.add(userDutyList.get(j));
                        }
                    }
                    //装配分组后的list
                    if (userDuties != null && userDuties.size() > 0) {
                        paixuUserDuty(userDuties);
                        userDutys.add(userDuties);
                    }
                }
            }
            return userDutys;
        }
        return null;
    }

    //lr  恩施考勤机接口
    public ToJson synAttend(String beginDate, String endDate) {
        List<AttendMachine> attendMachine = attendMachineMapper.selectMachine(new AttendMachine());
        if (attendMachine != null && attendMachine.size() > 0) {
            AttendMachine machine = attendMachine.get(0);
            String url = machine.getDatabaseIp();
            Map<String, Object> map = new HashMap<String, Object>();
            String sn = machine.getMachineBrand();
            map.put("starttime", beginDate);
            map.put("sn", sn);
            map.put("endtime", endDate);
            String param = com.alibaba.fastjson.JSONObject.toJSONString(map);
            String result = sendPost(url, param);
            List<Attend> attends = new ArrayList<>();
            if (result != null && !result.equals("")) {
                //反序列化转换对象
                TransactionResponse transactionResponse = JSON.parseObject(result, TransactionResponse.class);
                //System.out.println(transactionResponse);
                TransactionResponse.DataBean tdataBean = transactionResponse.getData();
                if (tdataBean != null) {
                    //获取数据
                    List<TransactionResponse.DataBean.ItemsBean> itemsBeans = tdataBean.getItems();
                    if (itemsBeans != null && itemsBeans.size() > 0) {
                        //按pin分组，创建set接受唯一pin
                        Set<String> pinSet = new HashSet<>();
                        for (TransactionResponse.DataBean.ItemsBean itemsBeana : itemsBeans) {
                            pinSet.add(itemsBeana.getPin());
                        }
                        //分组  创建map接受分组的数据
                        Map<String, List<TransactionResponse.DataBean.ItemsBean>> pinMap = new HashMap<>();
                        for (String pin : pinSet) {
                            List<TransactionResponse.DataBean.ItemsBean> itemsBeanList = new ArrayList<>();
                            for (TransactionResponse.DataBean.ItemsBean itemsBean : itemsBeans) {
                                if (pin.trim().equals(itemsBean.getPin().trim())) {
                                    itemsBeanList.add(itemsBean);
                                }
                            }
                            pinMap.put(pin, itemsBeanList);
                        }
                        //获取俩个日期中的所有日期
                        List<String> days = getDays(beginDate.split(" ")[0], endDate.split(" ")[0]);
                        //获取这些人的排班 数据
                        Map queryUserDutyMap = new HashMap();
                        queryUserDutyMap.put("pinSet", pinSet);
                        queryUserDutyMap.put("beginDate", beginDate.split(" ")[0]);
                        queryUserDutyMap.put("endDate", endDate.split(" ")[0]);
                        List<UserDuty> userDutyList = userDutyMapper.getUserDutyListByUserIdsAndDates(queryUserDutyMap);
                        if (userDutyList != null && userDutyList.size() > 0) {
                            //分组这些人的考勤
                            Map<String, List<UserDuty>> userDutyMap = groupUserDuty(pinSet, userDutyList);
                            if (userDutyMap != null) {
                                //检索每个人的考勤记录
                                for (String pin : pinSet) {
                                    //用户这期间排班情况
                                    List<UserDuty> userDutys = userDutyMap.get(pin);
                                    if (userDutys != null && userDutys.size() > 0) {
                                        //同步过来的记录
                                        List<TransactionResponse.DataBean.ItemsBean> itemsBeanList = pinMap.get(pin);
                                        Map<String, List<TransactionResponse.DataBean.ItemsBean>> dayItemsBeans = new HashMap<>();
                                        //按日期分组同步过来的数据
                                        for (String day : days) {
                                            List<TransactionResponse.DataBean.ItemsBean> dayDataBean = new ArrayList<>();
                                            for (TransactionResponse.DataBean.ItemsBean itemsBean : itemsBeanList) {
                                                if (itemsBean.getChecktime().contains(day)) {
                                                    dayDataBean.add(itemsBean);
                                                }
                                            }
                                            dayItemsBeans.put(day, dayDataBean);
                                        }
                                        //按日期分组用户的排班情况
                                        Map<String, UserDuty> userDutyMaps = new HashMap<>();
                                        for (String day : days) {
                                            for (UserDuty userDuty : userDutys) {
                                                if (userDuty.getDutyDate().equals(day)) {
                                                    userDutyMaps.put(day, userDuty);
                                                }
                                            }
                                        }
                                        //循环得到每一天
                                        for (String day : days) {
                                            //查看今天是否有排班？
                                            UserDuty userDuty = userDutyMaps.get(day);
                                            if (userDuty != null) {
                                                //查看用户今天是否已经有了签到记录，防止重复录入
                                                Integer res = attendMapper.getUidDateAttend(day, userDuty.getUid());
                                                if (res == null) {
                                                    List<TransactionResponse.DataBean.ItemsBean> dayItemsBeanList = dayItemsBeans.get(day);
                                                    if (dayItemsBeanList != null && dayItemsBeanList.size() > 0) {
                                                        //按时间分组
                                                        paixuAttend(dayItemsBeanList);
                                                        //当天最早签到记录
                                                        TransactionResponse.DataBean.ItemsBean itemsBean = dayItemsBeanList.get(0);
                                                        Attend attend = new Attend();
                                                        attend.setType("1");
                                                        attend.setUid(userDuty.getUid());
                                                        attend.setDate(DateFormat.DateToStr(day));
                                                        attend.setAtime(DateFormat.getTime(itemsBean.getChecktime()));
                                                        attend.setPhoneId("kaoqinji");
                                                        attend.setDevice(sn);
                                                        attend.setAddress("考勤机");
                                                        attend.setRemark("考勤机数据");
                                                        attends.add(attend);
                                                    }
                                                }
                                            }

                                        }

                                    }

                                }
                            }
                        }
                    }
                }
            }
            if (attends != null && attends.size() > 0) {
                int res = attendMapper.insertAttends(attends);
            }
            FileWriter osw = null;
            try {
                //输出日志
                String path = this.getClass().getResource("/").getPath().replaceFirst("/", "");
                String savePath = "";
                //如果是windows
                if (File.separator.equals("\\")) {
                    String[] split = path.split("webapps");
                    savePath = split[0] + savePath_win + "/attendBak";
                } else if (File.separator.equals("/")) {
                    String[] split = path.split("tomcat");
                    savePath = split[0] + savePath_linux + "/attendBak";
                }
                File file = new File(savePath);
                if (!file.exists()) {
                    file.mkdir();
                }
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
                String time = sdf.format(new Date());
                osw = new FileWriter(savePath + "/synAttnd" + time + ".txt", true);
                osw.write("得到的数据：   ");
                osw.write(result);
                osw.write("成功同步数据：   ");
                osw.write(attends.toString());
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (osw != null) {
                    try {
                        osw.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        ToJson toJson = new ToJson(0, "成功");
        return toJson;
    }

    /**
     * @创建作者:李然 Lr
     * @方法描述：分组
     * @创建时间：14:46 2019/4/23
     **/
    public Map<String, List<UserDuty>> groupUserDuty(Set<String> set, List<UserDuty> list) {
        Map<String, List<UserDuty>> map = new HashMap<>();
        for (String pin : set) {
            List<UserDuty> userDutyList = new ArrayList<>();
            for (UserDuty userDuty : list) {
                if (userDuty.getUserId().equals(pin)) {
                    userDutyList.add(userDuty);
                }
            }
            if (userDutyList.size() > 0) {
                map.put(pin, userDutyList);
            }
        }
        if (map.size() > 0) {
            return map;
        }
        return null;
    }

    public static String sendPost(String url, String param) {
        String result = "";
        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
        CloseableHttpResponse response = null;
        try {
            HttpPost httppost = new HttpPost(url);
            httppost.setHeader("Accept", "application/json");
            httppost.setHeader("Content-Type", "application/json");
            BasicHttpEntity requestBody = new BasicHttpEntity();
            requestBody.setContent(new ByteArrayInputStream(param.getBytes("UTF-8")));
            requestBody.setContentLength(param.getBytes("UTF-8").length);
            httppost.setEntity(requestBody);
// 执行客户端请求
            response = httpClient.execute(httppost);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                result = EntityUtils.toString(entity, "UTF-8");
            }
            //自动释放链接
            EntityUtils.consume(entity);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // 关闭连接
            // httpclient.getConnectionManager().shutdown();
            if (response != null) {
                try {
                    response.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (httpClient != null) {
                try {
                    httpClient.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }

    private void paixuAttend(List<TransactionResponse.DataBean.ItemsBean> dayItemsBeanList) {
        Collections.sort(dayItemsBeanList, new Comparator<TransactionResponse.DataBean.ItemsBean>() {
            @Override
            public int compare(TransactionResponse.DataBean.ItemsBean o1, TransactionResponse.DataBean.ItemsBean o2) {
                try {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    int flag = sdf.parse(o1.getChecktime()).compareTo(sdf.parse(o2.getChecktime()));
                    return flag;
                } catch (Exception e) {
                    System.out.println(e);
                }
                return 0;
            }
        });
    }

    /**
     * 根据时间查询全天中的出勤 迟到 请假 的统计
     *
     * @param date
     * @return
     */
    public BaseWrapper findListDateAll(String date) {
        AttendSetWrappers wrappers = new AttendSetWrappers();

        int chuqingLis = 0;
        int chidao = 0;
        int qingjia = 0;
        int jiaban=0;
        int yingchuqin=0;

        Integer userAll = 0;
        Integer userSize = 0;
        Map<Integer, AttendSet> attendSetMap = new HashMap<>();

        //1、查询条件
        Map<String, Object> map = new HashMap<>();
        map.put("beginDate", date);
        map.put("endDate", date);

        try {
            //所有符合条件的用户
            List<Integer> uids = attendMapper.getUidAll();
            //获取用户的排班信息
            List<List<UserDuty>> userDutys = getUserDutys(uids, map);
            if (userDutys != null) {
                userAll = userDutys.size();
                //每个用户的排班信息
                for (List<UserDuty> userDutyList : userDutys) {
                    //获取用户的uid
                    Integer uid = userDutyList.get(0).getUid();
                    Map<String, String> userAndDeptName = attendMapper.getUserNameAndDeptNameByUid(uid);
                    String userId = userAndDeptName.get("userid");
                    String userName = userAndDeptName.get("username");
                    String deptName = userAndDeptName.get("deptname");
                    //获取用户的签到信息
                    List<Attend> attendList = attendMapper.getAttendListByUidAndDates(uid, date, date);

                    //按照日期分组
                    Map<String, Map<String, Attend>> groudAttendMap = groudAttendByDateType(attendList);

                    //获取用户的排班信息
                    for (UserDuty userDuty : userDutyList) {
                        //当前用户的排班信息的考勤类型
                        Integer dutyType = userDuty.getDutyType();

                        //先查询在attendSetMap中是否存在，如果存在省去查数据库步骤，提高效率。
                        AttendSet attendSet = attendSetMap.get(dutyType);
                        if (attendSet == null) {
                            attendSet = attendSetMapper.selectAttendSetSid(dutyType);
                            attendSetMap.put(dutyType, attendSet);
                        }
                        //根据日期拿到attendMap attend考勤记录
                        Map<String, Attend> attendMap = groudAttendMap.get(userDuty.getDutyDate());

                        //如果当前没有考勤类型或者删除  的情况不考虑
                        if (attendSet != null) {
                            //应出勤
                            yingchuqin++;
                            if (attendMap != null) {
                                chuqingLis++;
                                userSize++;
                                try {
                                    for (int i = 1; i <= 6; i++) {
                                        Class c = attendSet.getClass().forName("com.xoa.model.attend.AttendSet");
                                        c.newInstance();
                                        Method methodget = c.getMethod("getAtime" + i + "Set");
                                        String getAtimeSet = (String) methodget.invoke(attendSet);
                                        if (getAtimeSet != null) {
                                            if (getAtimeSet.contains("|")) {
                                                String[] getAtimeSets = getAtimeSet.split("\\|");
                                                String kaiguan = getAtimeSets[0];
                                                String type = getAtimeSets[1];
                                                if (kaiguan.equals("1")) {
                                                    Attend attend = attendMap.get(String.valueOf(i));
                                                    Method methodGetAtime = c.getMethod("getAtime" + i);
                                                    String getAtime = (String) methodGetAtime.invoke(attendSet);
                                                    if (getAtime.length() < 10) {//兼容处理
                                                        getAtime = userDuty.getDutyDate() + " " + getAtime;
                                                    }
                                                    Method setAtimeSetother = c.getMethod("setAtime" + i + "Setother", new Class[]{String.class});
                                                    BaseSupplement dakaB = new BaseSupplement();
                                                    dakaB.setUid(uid);
                                                    dakaB.setName(userName);
                                                    dakaB.setDept(deptName);
                                                    if (attend != null) {
                                                        Integer atime = attend.getAtime();//秒级时间戳
                                                        String atimeStr = DateFormat.getStrTime(atime);
                                                        attend.setaTime(atimeStr);
                                                        if (atimeStr != null) {
                                                            String[] aTimeArray = atimeStr.split(" ");
                                                            if (aTimeArray.length > 1) {
                                                                setAtimeSetother.invoke(attendSet, new Object[]{aTimeArray[1]});
                                                            }

                                                        }
                                                        //应签到时间
                                                        Integer yAtime = DateFormat.getNowDateTime(getAtime);
                                                        attend.setyTime(getAtime);
                                                        dakaB.setStr("签到时间：" + atimeStr + "，(" + "应签到时间：" + getAtime + ")");
                                                        //下班
                                                        if (Integer.parseInt(type) != 2) {
                                                            if (atime > yAtime) {
                                                                chidao++;
                                                            }
                                                        }

                                                    }
                                                }

                                            }
                                        }
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                    }

                }
            }
            String endDate = date;
            if (date.length() < 11) {
                endDate = date + " 59:59:59";
            }

            //加班
            if (uids != null && uids.size() > 0) {
                List<Attend> attends = attendMapper.getJiaBanZhiBanListByUidsAndDate(uids, date);
                jiaban=attends.size();
            }

            //查询请假
            Map mapAtt = new HashMap();
            mapAtt.put("date", date);
            mapAtt.put("endDate", endDate);
            mapAtt.put("uids", uids);
            List<AttendLeave> attendLeaveList = attendLeaveMapper.getAttendLeaveByDateAndUids(mapAtt);
            if (attendLeaveList != null && attendLeaveList.size() > 0) {
                for (AttendLeave attendLeave : attendLeaveList) {
                    qingjia++;
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        //返回信息
        Map<String, Integer> data = new HashMap<>();
        data.put("qingjia", qingjia);
        data.put("chidao", chidao);
        data.put("chuqin", chuqingLis);
        data.put("jiaban",jiaban);
        data.put("yingchuqin",yingchuqin);

        wrappers.setFlag(true);
        wrappers.setStatus(true);
        wrappers.setData(data);
        return wrappers;
    }

    /**
     * 根据时间统计一周的考勤统计
     *
     * @param beginDate
     * @param endDate
     * @return
     */
    public BaseWrapper queryDateAll(String beginDate, String endDate) {
        AttendSetWrappers wrappers = new AttendSetWrappers();
        //用于存放考勤类型
        Map<Integer, AttendSet> attendSetMap = new HashMap<>();


        //出勤一周总统计
        int chuqin = 0;
        //迟到一周总统计
        int chidao = 0;
        //请假一周总统计
        int qingjia = 0;

        //存放出勤对应天数
        List<Integer> chuqinDataList = new ArrayList<>();
        //存放请假对应天数
        List<Integer> qingjiaDataList = new ArrayList<>();
        //存放迟到出勤对应天数
        List<Integer> chidaoDataList = new ArrayList<>();

        //存放出勤日期
        List chuqinDate = new ArrayList();
        //存放迟到日期
        List chidaoDate = new ArrayList();
        //存放请假日期
        List qingjiaDate = new ArrayList();


        //存放uid
        List<Integer> uids = new ArrayList<>();

        try {
            //用于查询请假是的时间范围
            String endStr = endDate;

            //用于统计时间的中间变量
            String beginStr = beginDate;
            //根据传入的时间范围拿到每一天
            List<String> date = new ArrayList();


            //拿到时间范围内的日期
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            if (getIntegerTime(beginStr) <= getIntegerTime(endStr)) {
//                    date.add(beginStr);
                Date dateStr = df.parse(beginStr);
                Date dateEnd = df.parse(endStr);
                long strTime = dateStr.getTime();
                long eTime = dateEnd.getTime();
                Long cha = eTime - strTime;
                Long day = cha / (24 * 60 * 60 * 1000) + 1;
                for (int i = 0; i < day; i++) {
                    date.add(beginStr);
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(dateStr);
                    calendar.add(Calendar.DAY_OF_MONTH, 1);//加一天
                    dateStr = calendar.getTime();
                    beginStr = df.format(calendar.getTime());

                }


            }


            for (int k = 0; k < date.size(); k++) {
                //每一天的时间
                String begin = date.get(k);

                //存放每一天的统计
                int chuqinNum = 0;
                int chidaoNum = 0;
                int qingjiaNum = 0;


                //1、查询条件
                Map<String, Object> map = new HashMap<>();
                map.put("beginDate", begin);
                map.put("endDate", begin + " 23:59:59");

                //查询所有用户的uid
                uids = attendMapper.getUidAll();

                //获取用户的排班信息
                List<List<UserDuty>> userDutys = getUserDutys(uids, map);
                if (userDutys != null) {
                    //每个用户的排班信息
                    for (List<UserDuty> userDutyList : userDutys) {

                        Integer uid = userDutyList.get(0).getUid();
//                        uidSet.add(uid);
                        //拿到用户的考勤记录
                        List<Attend> attendList = attendMapper.getAttendListByUidAndDates(uid, beginDate, endDate);
                        //按照日期分组
                        Map<String, Map<String, Attend>> groudAttendMap = groudAttendByDateType(attendList);
                        //获取每个用户集体排班信息
                        for (UserDuty userDuty : userDutyList) {
                            //当前用户的排班信息的考勤类型
                            Integer dutyType = userDuty.getDutyType();
                            //如果attendSetMap中存放考勤类型，就不需要存数据库中查询
                            AttendSet attendSet = attendSetMap.get(dutyType);
                            if (attendSet == null) {
                                attendSet = attendSetMapper.selectAttendSetSid(dutyType);
                                attendSetMap.put(dutyType, attendSet);
                            }
                            //根据日期拿到attendMap attend考勤记录
                            Map<String, Attend> attendMap = groudAttendMap.get(userDuty.getDutyDate());
                            //如果不存在考勤 就不考虑
                            if (attendSet != null) {
                                if (attendMap != null) {
                                    chuqin++;
                                    chuqinNum++;
                                    try {
                                        for (int i = 1; i <= 6; i++) {
                                            Class c = attendSet.getClass().forName("com.xoa.model.attend.AttendSet");
                                            c.newInstance();
                                            Method methodget = c.getMethod("getAtime" + i + "Set");
                                            String getAtimeSet = (String) methodget.invoke(attendSet);
                                            if (getAtimeSet != null) {
                                                if (getAtimeSet.contains("|")) {
                                                    String[] getAtimeSets = getAtimeSet.split("\\|");
                                                    String kaiguan = getAtimeSets[0];
                                                    String type = getAtimeSets[1];
                                                    if (kaiguan.equals("1")) {
                                                        Attend attend = attendMap.get(String.valueOf(i));
                                                        Method methodGetAtime = c.getMethod("getAtime" + i);
                                                        String getAtime = (String) methodGetAtime.invoke(attendSet);
                                                        if (getAtime.length() < 10) {//兼容处理
                                                            getAtime = userDuty.getDutyDate() + " " + getAtime;
                                                        }
                                                        Method setAtimeSetother = c.getMethod("setAtime" + i + "Setother", new Class[]{String.class});

                                                        if (attend != null) {
                                                            Integer atime = attend.getAtime();//秒级时间戳
                                                            String atimeStr = DateFormat.getStrTime(atime);
                                                            attend.setaTime(atimeStr);
                                                            if (atimeStr != null) {
                                                                String[] aTimeArray = atimeStr.split(" ");
                                                                if (aTimeArray.length > 1) {
                                                                    setAtimeSetother.invoke(attendSet, new Object[]{aTimeArray[1]});
                                                                }

                                                            }
                                                            //应签到时间
                                                            Integer yAtime = DateFormat.getNowDateTime(getAtime);
                                                            attend.setyTime(getAtime);
//
                                                            //上班
                                                            if (Integer.parseInt(type) != 2) {
                                                                if (atime > yAtime) {
                                                                    chidao++;
                                                                    chidaoNum++;
                                                                    chidaoDate.add(atimeStr);
                                                                }
                                                                chuqinDate.add(atimeStr);
                                                            }

                                                        }
                                                    }

                                                }
                                            }
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }

                                }
                            }

                        }


                    }

                }

//                int listCount=0;
//                //遍历每个用户对应时间范围内的考勤统计
//                for(Map.Entry<Integer,List<Integer>> entry : chuqinMap.entrySet()) {
//                    int userNum=0;//单个人员在时间范围内出勤天数
//                    List<Integer> list = entry.getValue();
//                    listCount=list.size();
//                    break;
//                }
//
//
//                //遍历一天中每个用户的统计
//                for(int i=0;i<listCount;i++){
//                    Integer dayCount=0;
//                    for(Integer uid:uidSet){
//                        Integer uidDay=chuqinMap.get(uid).get(i);
//                        dayCount+=uidDay;
//                    }
//                    chuqinDateList.add(dayCount);
//                }

                chuqinDataList.add(chuqinNum);
                chidaoDataList.add(chidaoNum);

            }
//            String endDateStr = endStr;
            if (endDate.length() < 11) {
                endDate = endDate + " 23:59:59";
            }
            Map mapAtt = new HashMap();
            mapAtt.put("date", beginDate);
            mapAtt.put("endDate", endDate);
            mapAtt.put("uids", uids);
            //查询请假
            List<AttendLeave> attendLeaveList = attendLeaveMapper.getAttendLeaveByDateAndUids(mapAtt);
            if (attendLeaveList != null && attendLeaveList.size() > 0) {
                for (AttendLeave attendLeave : attendLeaveList) {


                    Date dbBeginDate = attendLeave.getLeaveDate1();
                    Date dbEndDate = attendLeave.getLeaveDate2();
                    String stratTime = beginDate;
                    String endTime = endDate;
                    //如果用户xx开始时间大于搜索的开始时间，那么起始时间为用户时间
                    if (getIntegerTime(dbBeginDate) > getIntegerTime(beginDate)) {
                        stratTime = DateFormat.getStrDate(dbBeginDate);
                    }
                    //如果用户xx结束时间小于搜索的开始时间，那么结束时间为用户时间
                    if (getIntegerTime(dbEndDate) < getIntegerTime(endDate)) {
                        endTime = DateFormat.getStrDate(dbEndDate);
                    }
                    List<String> days = getDays(stratTime, endTime);
                    for (String day : days) {
                        qingjiaDate.add(day);
                    }
////                    Double daysDouble = getAttendDays(stratTime, endTime);
                    qingjia += days.size();
                }
            }

            for (int i = 0; i < date.size(); i++) {
                //统计一天请假数据
                int qingjiaData = 0;
                for (int j = 0; j < qingjiaDate.size(); j++) {
                    if (date.get(i).equals(qingjiaDate.get(j))) {
                        qingjiaData++;
                    } else {
                        qingjiaData += 0;
                    }
                }
                qingjiaDataList.add(qingjiaData);
            }


        } catch (Exception e) {
            e.printStackTrace();
        }

        //最终数据统计
        Map<String, Map> data = new HashMap<>();

        //存放出勤统计
        Map<String, Object> chuqinMap = new HashMap<>();
        //存放请假统计
        Map<String, Object> qingjiaMap = new HashMap<>();
        //存放迟到统计
        Map<String, Object> chidaoMap = new HashMap<>();


        chuqinMap.put("legend", chuqin);
        chuqinMap.put("num", chuqinDataList);
        chuqinMap.put("date", chuqinDate);

        chidaoMap.put("legend", chidao);
        chidaoMap.put("num", chidaoDataList);
        chidaoMap.put("date", chidaoDate);

        qingjiaMap.put("legend", qingjia);
        qingjiaMap.put("num", qingjiaDataList);
        qingjiaMap.put("date", qingjiaDate);

        data.put("chuqin", chuqinMap);
        data.put("chidao", chidaoMap);
        data.put("qingjia", qingjiaMap);

        wrappers.setFlag(true);
        wrappers.setStatus(true);
        wrappers.setData(data);
        return wrappers;
    }

    //装配attendSet
    public static void setAttendSet(AttendSet attendSet) throws Exception {
        Class c = attendSet.getClass().forName("com.xoa.model.attend.AttendSet");
        c.newInstance();
        Map<String, String> map = new HashMap<String, String>();
        Map<String, String> map1 = new HashMap<String, String>();
        Map<String, String> map2 = new HashMap<String, String>();
        for (int i = 1; i <= 6; i++) {
            //分别取出 开关 和上下班类型
            Method methodget = c.getMethod("getAtime" + i + "Set");
            String getAtimeSet = (String) methodget.invoke(attendSet);
            String[] getAtimeSets = getAtimeSet.split("\\|");
            String setother = getAtimeSets[0];
            String commute = getAtimeSets[1];
            //开关
            Method method = c.getMethod("setAtime" + i + "Setother", String.class);
            method.invoke(attendSet, setother);
            //上下班
            Method method1 = c.getMethod("setCommute" + i, String.class);
            method1.invoke(attendSet, commute);

            Method method2 = c.getMethod("getAtime" + i + "Setother");
            map.put("atime" + i + "Setother", (String) method2.invoke(attendSet));

            Method method3 = c.getMethod("getCommute" + i);
            map1.put("commute" + i, (String) method3.invoke(attendSet));
            method3.invoke(attendSet);

            Method method4 = c.getMethod("getAtime" + i);
            map2.put("atime" + i, (String) method4.invoke(attendSet));
        }
        attendSet.setAtimeSetotherList(map);
        attendSet.setCommuteList(map1);
        attendSet.setTimeList(map2);
        //ip段分割
        if (!StringUtils.checkNull(attendSet.getIpParagraph())) {
            String[] ipParagraph = attendSet.getIpParagraph().split("-");
            attendSet.setiPStart(ipParagraph[0]);
            attendSet.setiPEnd(ipParagraph[1]);
        }
    }


    //装配attendSet(考勤统计)
    public static void setAttendStaSet(AttendSet attendSet) throws Exception {
        Class c = attendSet.getClass().forName("com.xoa.model.attend.AttendSet");
        c.newInstance();
        Map<String, String> map = new HashMap<String, String>();
        Map<String, String> map1 = new HashMap<String, String>();
        Map<String, String> map2 = new HashMap<String, String>();
        for (int i = 1; i <= 6; i++) {
            //分别取出 开关 和上下班类型
            Method methodget = c.getMethod("getAtime" + i + "Set");
            String getAtimeSet = (String) methodget.invoke(attendSet);
            String[] getAtimeSets = getAtimeSet.split("\\|");
            String setother = getAtimeSets[0];
            String commute = getAtimeSets[1];
            //开关
            Method method = c.getMethod("setAtime" + i + "Setother", String.class);
            method.invoke(attendSet, setother);
            //上下班
            Method method1 = c.getMethod("setCommute" + i, String.class);
            method1.invoke(attendSet, commute);

            Method method2 = c.getMethod("getAtime" + i + "Setother");
            map.put("atime" + i + "Setother", (String) method2.invoke(attendSet));

            Method method3 = c.getMethod("getCommute" + i);
            map1.put("commute" + i, (String) method3.invoke(attendSet));
            method3.invoke(attendSet);

            Method method4 = c.getMethod("getAtime" + i);
            map2.put("atime" + i, (String) method4.invoke(attendSet));
        }
        attendSet.setAtimeSetotherList(map);
        attendSet.setCommuteList(map1);
        attendSet.setTimeList(map2);
    }
    //季度请假，加班，出差数据获取
    public ToJson queryCountDataByQuarter(HttpServletRequest request){
        ToJson json=new ToJson();
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionCookie);


        SimpleDateFormat longSdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date currentQuarterStartTime = DateFormat.getCurrentQuarterStartTime();
        Date currentQuarterEndTime = DateFormat.getCurrentQuarterEndTime();

        BaseAttend jiaBan = this.getJiaBan(user.getUserId(), longSdf.format(currentQuarterStartTime), longSdf.format(currentQuarterEndTime));
        BaseAttend qingJia = this.getQingJia(user.getUserId(), longSdf.format(currentQuarterStartTime), longSdf.format(currentQuarterEndTime));
        BaseAttend chuChai = this.getChuChai(user.getUserId(), longSdf.format(currentQuarterStartTime), longSdf.format(currentQuarterEndTime));

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("jiaBan",jiaBan.getDays());
        map.put("qingJia",qingJia.getDays());
        map.put("chuChai",chuChai.getDays());

        json.setObject(map);
        json.setMsg("ok");
        json.setFlag(0);
        return  json;
    }
    //月度请假，加班，出差数据获取
    public ToJson queryCountDataByMonth(HttpServletRequest request){
        ToJson json=new ToJson();
        Map<String, Object> map = new HashMap<String, Object>();
        SimpleDateFormat longSdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionCookie);
        Date currentMonthStartTime = DateFormat.getCurrentMonthStartTime();
        Date currentMonthEndTime = DateFormat.getCurrentMonthEndTime();
        BaseAttend jiaBan = this.getJiaBan(user.getUserId(), longSdf.format(currentMonthStartTime), longSdf.format(currentMonthEndTime));
        BaseAttend qingJia = this.getQingJia(user.getUserId(), longSdf.format(currentMonthStartTime), longSdf.format(currentMonthEndTime));
        BaseAttend chuChai = this.getChuChai(user.getUserId(), longSdf.format(currentMonthStartTime), longSdf.format(currentMonthEndTime));
        map.put("jiaBan",jiaBan.getItem());
        map.put("qingJia",qingJia.getItem());
        map.put("chuChai",chuChai.getItem());
        json.setObject(map);
        json.setMsg("ok");
        json.setFlag(0);
        return  json;
    }
    //年度请假，加班，出差数据获取
    public ToJson queryCountDataByYear(HttpServletRequest request){
        ToJson json=new ToJson();
        Map<String, Object> map = new HashMap<String, Object>();
        SimpleDateFormat longSdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionCookie);
        Date currentYearStartTime = DateFormat.getCurrentYearStartTime();
        Date currentYearEndTime = DateFormat.getCurrentYearEndTime();
        BaseAttend jiaBan = this.getJiaBan(user.getUserId(), longSdf.format(currentYearStartTime), longSdf.format(currentYearEndTime));
        BaseAttend qingJia = this.getQingJia(user.getUserId(), longSdf.format(currentYearStartTime), longSdf.format(currentYearEndTime));
        BaseAttend chuChai = this.getChuChai(user.getUserId(), longSdf.format(currentYearStartTime), longSdf.format(currentYearEndTime));
        map.put("jiaBan",jiaBan.getDays());
        map.put("qingJia",qingJia.getDays());
        map.put("chuChai",chuChai.getDays());
        json.setObject(map);
        json.setMsg("ok");
        json.setFlag(0);
        return  json;
    }

    public ToJson findCountDay(HttpServletRequest request) {
        ToJson toJson=new ToJson(1,"暂无数据");
        try {
            Map<Integer, AttendSet> attendSetMap = new HashMap<>();
            //1、查询条件
            Map<String, Object> map = new HashMap<>();
            map.put("beginDate", new Date());
            map.put("endDate", new Date());

            //所有符合条件的用户
            List<Integer> uids = attendMapper.getUidAll();

        }catch (Exception e){
            toJson.setMsg(e.getMessage());
        }
        return toJson;
    }
}